From 28500d2cdfa9e8a46deef83155f7bd2a728cb552 Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 9 Jun 2020 09:36:10 +0200 Subject: [PATCH 1/4] 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 ========") From 97c32396571fa74dea85afa2753fb60922e98767 Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 9 Jun 2020 09:36:34 +0200 Subject: [PATCH 2/4] Explicitly delete xbmc.Monitor() and xbmc.Player() --- resources/lib/service_entry.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index c80f0c62..dc732ff1 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -556,6 +556,11 @@ class Service(object): library_sync.clear_window_vars() # Will block until threads have quit 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(): From da671c8ee53e4f7080a1816cd6f305ac647a601f Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 9 Jun 2020 09:37:18 +0200 Subject: [PATCH 3/4] Do not instantiate xbmc.Monitor() if possible (guess this leads to issues if we should shut down) --- resources/lib/app/application.py | 4 ++-- resources/lib/backgroundthread.py | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/resources/lib/app/application.py b/resources/lib/app/application.py index 364345d2..79608afd 100644 --- a/resources/lib/app/application.py +++ b/resources/lib/app/application.py @@ -134,7 +134,7 @@ class App(object): thread.suspend(block=True) else: break - return xbmc.Monitor().abortRequested() + return self.monitor.abortRequested() def resume_threads(self): """ @@ -144,7 +144,7 @@ class App(object): LOG.debug('Resuming threads: %s', self.threads) for thread in self.threads: thread.resume() - return xbmc.Monitor().abortRequested() + return self.monitor.abortRequested() def stop_threads(self, block=True): """ diff --git a/resources/lib/backgroundthread.py b/resources/lib/backgroundthread.py index 77a068fe..831b3274 100644 --- a/resources/lib/backgroundthread.py +++ b/resources/lib/backgroundthread.py @@ -8,8 +8,6 @@ import Queue import heapq from collections import deque -import xbmc - from . import utils, app, variables as v WORKER_COUNT = 3 @@ -305,7 +303,7 @@ class Task(object): self._canceled = True def should_cancel(self): - return self._canceled or xbmc.Monitor().abortRequested() + return self._canceled or app.APP.monitor.abortRequested() def isValid(self): return not self.finished and not self._canceled @@ -370,7 +368,7 @@ class BackgroundWorker(object): return self def aborted(self): - return self._abort or xbmc.Monitor().abortRequested() + return self._abort or app.APP.monitor.abortRequested() def start(self): if self._thread and self._thread.isAlive(): @@ -452,7 +450,7 @@ class BackgroundThreader: return self def aborted(self): - return self._abort or xbmc.Monitor().abortRequested() + return self._abort or app.APP.monitor.abortRequested() def shutdown(self, block=True): self.abort() From f747086957ac0ff987d25300c2c280660dd004ba Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 9 Jun 2020 09:54:47 +0200 Subject: [PATCH 4/4] Migration: make sure user needs to sign in again after PKC update --- resources/lib/migration.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/lib/migration.py b/resources/lib/migration.py index 1aac3c11..e99e3210 100644 --- a/resources/lib/migration.py +++ b/resources/lib/migration.py @@ -90,4 +90,13 @@ def check_migration(): from .playlists import 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)