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)

This commit is contained in:
croneter 2020-06-09 09:36:10 +02:00
parent 038477fa77
commit 28500d2cdf

View file

@ -37,6 +37,10 @@ class Service(object):
def __init__(self): def __init__(self):
self._init_done = False 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? # Kodi Version supported by PKC?
try: try:
v.database_paths() v.database_paths()
@ -100,9 +104,11 @@ class Service(object):
self.auth_running = False self.auth_running = False
self._init_done = True self._init_done = True
@staticmethod def should_cancel(self):
def should_cancel(): if self.profile != utils.window('plex_kodi_profilepath'):
return xbmc.Monitor().abortRequested() or app.APP.stop_pkc 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): def on_connection_check(self, result):
""" """
@ -553,28 +559,6 @@ class Service(object):
def start(): 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')) DELAY = int(utils.settings('startupDelay'))
LOG.info("Delaying Plex startup by: %s sec...", DELAY) LOG.info("Delaying Plex startup by: %s sec...", DELAY)
if DELAY and xbmc.Monitor().waitForAbort(DELAY): if DELAY and xbmc.Monitor().waitForAbort(DELAY):
@ -582,5 +566,4 @@ def start():
LOG.info("Abort requested while waiting. PKC not started.") LOG.info("Abort requested while waiting. PKC not started.")
else: else:
Service().ServiceEntryPoint() Service().ServiceEntryPoint()
utils.window('plex_service_started', clear=True)
LOG.info("======== STOP PlexKodiConnect service ========") LOG.info("======== STOP PlexKodiConnect service ========")