mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-22 13:30:36 +01:00
Wait for service init on start, reuse existing service
This commit is contained in:
parent
7ee0171ec7
commit
bec6bda2f6
@ -105,25 +105,27 @@ class SidebandApp(MDApp):
|
||||
|
||||
if self.sideband.first_run:
|
||||
self.guide_action()
|
||||
self.request_notifications_permission()
|
||||
self.request_permissions()
|
||||
else:
|
||||
self.open_conversations()
|
||||
|
||||
self.app_state = SidebandApp.ACTIVE
|
||||
|
||||
def start_service(self):
|
||||
RNS.log("Launching platform service for RNS and LXMF")
|
||||
RNS.log("Launching platform-specific service for RNS and LXMF")
|
||||
if RNS.vendor.platformutils.get_platform() == "android":
|
||||
# TODO: Check if service is running and start as necessary
|
||||
self.android_service = autoclass('io.unsigned.sideband.ServiceSidebandservice')
|
||||
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
|
||||
argument = self.app_dir
|
||||
self.android_service.start(mActivity, argument)
|
||||
|
||||
# TODO: Remove and add real service started check here
|
||||
RNS.log("Service instance: "+str(self.android_service))
|
||||
RNS.log("Waiting for service start")
|
||||
time.sleep(7)
|
||||
# Wait a little extra for user to react to permissions prompt
|
||||
if self.sideband.first_run:
|
||||
time.sleep(6)
|
||||
|
||||
# Wait for service to become available
|
||||
while not self.sideband.service_available():
|
||||
time.sleep(0.20)
|
||||
|
||||
# Start local core instance
|
||||
self.sideband.start()
|
||||
|
@ -145,6 +145,7 @@ class SidebandService():
|
||||
|
||||
def run(self):
|
||||
while self.should_run:
|
||||
self.sideband.setstate("service.heartbeat", time.time())
|
||||
time.sleep(1)
|
||||
|
||||
self.release_locks()
|
||||
|
@ -375,6 +375,19 @@ class SidebandCore():
|
||||
else:
|
||||
return []
|
||||
|
||||
def service_available(self):
|
||||
service_heartbeat = self.getstate("service.heartbeat")
|
||||
if not service_heartbeat:
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
if time.time() - service_heartbeat > 2.5:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def gui_foreground(self):
|
||||
return self._db_getstate("app.foreground")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user