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:
|
if self.sideband.first_run:
|
||||||
self.guide_action()
|
self.guide_action()
|
||||||
self.request_notifications_permission()
|
self.request_permissions()
|
||||||
else:
|
else:
|
||||||
self.open_conversations()
|
self.open_conversations()
|
||||||
|
|
||||||
self.app_state = SidebandApp.ACTIVE
|
self.app_state = SidebandApp.ACTIVE
|
||||||
|
|
||||||
def start_service(self):
|
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":
|
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')
|
self.android_service = autoclass('io.unsigned.sideband.ServiceSidebandservice')
|
||||||
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
|
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
|
||||||
argument = self.app_dir
|
argument = self.app_dir
|
||||||
self.android_service.start(mActivity, argument)
|
self.android_service.start(mActivity, argument)
|
||||||
|
|
||||||
# TODO: Remove and add real service started check here
|
# Wait a little extra for user to react to permissions prompt
|
||||||
RNS.log("Service instance: "+str(self.android_service))
|
if self.sideband.first_run:
|
||||||
RNS.log("Waiting for service start")
|
time.sleep(6)
|
||||||
time.sleep(7)
|
|
||||||
|
# Wait for service to become available
|
||||||
|
while not self.sideband.service_available():
|
||||||
|
time.sleep(0.20)
|
||||||
|
|
||||||
# Start local core instance
|
# Start local core instance
|
||||||
self.sideband.start()
|
self.sideband.start()
|
||||||
|
@ -145,6 +145,7 @@ class SidebandService():
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.should_run:
|
while self.should_run:
|
||||||
|
self.sideband.setstate("service.heartbeat", time.time())
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
self.release_locks()
|
self.release_locks()
|
||||||
|
@ -375,6 +375,19 @@ class SidebandCore():
|
|||||||
else:
|
else:
|
||||||
return []
|
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):
|
def gui_foreground(self):
|
||||||
return self._db_getstate("app.foreground")
|
return self._db_getstate("app.foreground")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user