Merge pull request #1185 from croneter/fix-users

Fix PKC shutdown on Kodi profile switch
This commit is contained in:
croneter 2020-06-09 12:06:26 +02:00 committed by GitHub
commit 9c1a753fa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 33 deletions

View file

@ -134,7 +134,7 @@ class App(object):
thread.suspend(block=True) thread.suspend(block=True)
else: else:
break break
return xbmc.Monitor().abortRequested() return self.monitor.abortRequested()
def resume_threads(self): def resume_threads(self):
""" """
@ -144,7 +144,7 @@ class App(object):
LOG.debug('Resuming threads: %s', self.threads) LOG.debug('Resuming threads: %s', self.threads)
for thread in self.threads: for thread in self.threads:
thread.resume() thread.resume()
return xbmc.Monitor().abortRequested() return self.monitor.abortRequested()
def stop_threads(self, block=True): def stop_threads(self, block=True):
""" """

View file

@ -8,8 +8,6 @@ import Queue
import heapq import heapq
from collections import deque from collections import deque
import xbmc
from . import utils, app, variables as v from . import utils, app, variables as v
WORKER_COUNT = 3 WORKER_COUNT = 3
@ -305,7 +303,7 @@ class Task(object):
self._canceled = True self._canceled = True
def should_cancel(self): def should_cancel(self):
return self._canceled or xbmc.Monitor().abortRequested() return self._canceled or app.APP.monitor.abortRequested()
def isValid(self): def isValid(self):
return not self.finished and not self._canceled return not self.finished and not self._canceled
@ -370,7 +368,7 @@ class BackgroundWorker(object):
return self return self
def aborted(self): def aborted(self):
return self._abort or xbmc.Monitor().abortRequested() return self._abort or app.APP.monitor.abortRequested()
def start(self): def start(self):
if self._thread and self._thread.isAlive(): if self._thread and self._thread.isAlive():
@ -452,7 +450,7 @@ class BackgroundThreader:
return self return self
def aborted(self): def aborted(self):
return self._abort or xbmc.Monitor().abortRequested() return self._abort or app.APP.monitor.abortRequested()
def shutdown(self, block=True): def shutdown(self, block=True):
self.abort() self.abort()

View file

@ -90,4 +90,13 @@ def check_migration():
from .playlists import remove_synced_playlists from .playlists import remove_synced_playlists
remove_synced_playlists() remove_synced_playlists()
if not utils.compare_version(last_migration, '2.12.2'):
LOG.info('Migrating to version 2.12.1')
# Sign user out to make sure he needs to sign in again
utils.settings('username', value='')
utils.settings('userid', value='')
utils.settings('plex_restricteduser', value='')
utils.settings('accessToken', value='')
utils.settings('plexAvatar', value='')
utils.settings('last_migrated_PKC_version', value=v.ADDON_VERSION) utils.settings('last_migrated_PKC_version', value=v.ADDON_VERSION)

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):
""" """
@ -550,31 +556,14 @@ class Service(object):
library_sync.clear_window_vars() library_sync.clear_window_vars()
# Will block until threads have quit # Will block until threads have quit
app.APP.stop_threads() app.APP.stop_threads()
# CLEANUP
# Kodi's xbmc.Monitor() stalls
# delete xbmc.Player() just to be sure
del app.APP.monitor
del app.APP.player
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 +571,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 ========")