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:
parent
038477fa77
commit
28500d2cdf
1 changed files with 9 additions and 26 deletions
|
@ -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 ========")
|
||||
|
|
Loading…
Reference in a new issue