From 28500d2cdfa9e8a46deef83155f7bd2a728cb552 Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 9 Jun 2020 09:36:10 +0200 Subject: [PATCH] Correctly detect PKC shutdown and ensure that a PKC instance is always running (guess invoking xbmc.Monitor() while we should shut down did not help) --- resources/lib/service_entry.py | 35 +++++++++------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index 8f1a5c2f..c80f0c62 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -37,6 +37,10 @@ class Service(object): def __init__(self): self._init_done = False + # Detect switch of Kodi profile - a second instance of PKC is started + self.profile = xbmc.translatePath('special://profile') + utils.window('plex_kodi_profilepath', value=self.profile) + # Kodi Version supported by PKC? try: v.database_paths() @@ -100,9 +104,11 @@ class Service(object): self.auth_running = False self._init_done = True - @staticmethod - def should_cancel(): - return xbmc.Monitor().abortRequested() or app.APP.stop_pkc + def should_cancel(self): + if self.profile != utils.window('plex_kodi_profilepath'): + LOG.info('Kodi profile switch detected, shutting this instance down') + return True + return app.APP.monitor.abortRequested() or app.APP.stop_pkc def on_connection_check(self, result): """ @@ -553,28 +559,6 @@ class Service(object): def start(): - # Safety net - Kody starts PKC twice upon first installation! - if utils.window('plex_service_started') == 'true': - LOG.info('Another service.py instance is already running - shutting ' - 'it down now') - # Telling the other Python instance of PKC to shut down now - i = 0 - while utils.window('plexkodiconnect.command'): - xbmc.sleep(20) - i += 1 - if i > 300: - LOG.error('Could not tell other PKC instance to shut down') - return - utils.window('plexkodiconnect.command', value='EXIT-PKC') - # Telling successful - now wait for actual shut-down - i = 0 - while utils.window('plex_service_started'): - xbmc.sleep(20) - i += 1 - if i > 300: - LOG.error('Could not shut down other PKC instance') - return - utils.window('plex_service_started', value='true') DELAY = int(utils.settings('startupDelay')) LOG.info("Delaying Plex startup by: %s sec...", DELAY) if DELAY and xbmc.Monitor().waitForAbort(DELAY): @@ -582,5 +566,4 @@ def start(): LOG.info("Abort requested while waiting. PKC not started.") else: Service().ServiceEntryPoint() - utils.window('plex_service_started', clear=True) LOG.info("======== STOP PlexKodiConnect service ========")