From c34f43ceadcb4de6260b1b2a3ca2295279e2a59f Mon Sep 17 00:00:00 2001 From: croneter Date: Thu, 7 May 2020 08:37:49 +0200 Subject: [PATCH] Fix websocket threads not getting suspended correctly --- resources/lib/app/__init__.py | 8 ++++++++ resources/lib/app/libsync.py | 6 ++++-- resources/lib/service_entry.py | 1 + resources/lib/websocket_client.py | 19 ++++++++++++++----- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/resources/lib/app/__init__.py b/resources/lib/app/__init__.py index c224d7b9..1788d304 100644 --- a/resources/lib/app/__init__.py +++ b/resources/lib/app/__init__.py @@ -30,3 +30,11 @@ def init(entrypoint=False): SYNC = Sync(entrypoint) if not entrypoint: PLAYSTATE = PlayState() + +def reload(): + """ + Reload PKC settings from xml file, e.g. on user-switch + """ + global APP, SYNC + APP.reload() + SYNC.reload() diff --git a/resources/lib/app/libsync.py b/resources/lib/app/libsync.py index 51862e10..3fb37887 100644 --- a/resources/lib/app/libsync.py +++ b/resources/lib/app/libsync.py @@ -100,7 +100,6 @@ class Sync(object): self.artwork = utils.settings('usePlexArtwork') == 'true' self.replace_smb_path = utils.settings('replaceSMB') == 'true' self.remap_path = utils.settings('remapSMB') == 'true' - self.force_transcode_pix = utils.settings('force_transcode_pix') == 'true' self.remapSMBmovieOrg = remove_trailing_slash(utils.settings('remapSMBmovieOrg')) self.remapSMBmovieNew = remove_trailing_slash(utils.settings('remapSMBmovieNew')) self.remapSMBtvOrg = remove_trailing_slash(utils.settings('remapSMBtvOrg')) @@ -111,7 +110,6 @@ class Sync(object): self.remapSMBphotoNew = remove_trailing_slash(utils.settings('remapSMBphotoNew')) self.escape_path = utils.settings('escapePath') == 'true' self.indicate_media_versions = utils.settings('indicate_media_versions') == "true" - self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true' self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true' self.sync_specific_kodi_playlists = utils.settings('syncSpecificKodiPlaylists') == 'true' self.sync_thread_number = int(utils.settings('syncThreadNumber')) @@ -129,3 +127,7 @@ class Sync(object): self.backgroundsync_saftymargin = int(utils.settings('backgroundsync_saftyMargin')) self.image_sync_notifications = utils.settings('imageSyncNotifications') == 'true' + + self.force_transcode_pix = utils.settings('force_transcode_pix') == 'true' + # Trailers in Kodi DB will remain UNTIL DB is reset! + self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true' diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index b2870a18..8f1a5c2f 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -248,6 +248,7 @@ class Service(object): icon='{plex}', time=2000, sound=False) + app.reload() app.APP.resume_threads() self.auth_running = False diff --git a/resources/lib/websocket_client.py b/resources/lib/websocket_client.py index b18510d3..5cca4752 100644 --- a/resources/lib/websocket_client.py +++ b/resources/lib/websocket_client.py @@ -142,9 +142,13 @@ class PMS_Websocket(WebSocket): """ def should_suspend(self): """ - Returns True if the thread is suspended + Returns True if the thread is suspended. """ - return self._suspended or app.SYNC.background_sync_disabled + suspend = self._suspended or app.SYNC.background_sync_disabled + if suspend: + # This thread needs to clear the Event() _is_not_suspended itself! + self.suspend() + return suspend def getUri(self): if self.redirect_uri: @@ -209,9 +213,14 @@ class Alexa_Websocket(WebSocket): """ Overwrite method since we need to check for plex token """ - return (self._suspended or - not app.ACCOUNT.plex_token or - app.ACCOUNT.restricted_user) + suspend = self._suspended or \ + not app.SYNC.enable_alexa or \ + not app.ACCOUNT.plex_token or \ + app.ACCOUNT.restricted_user + if suspend: + # This thread needs to clear the Event() _is_not_suspended itself! + self.suspend() + return suspend def getUri(self): if self.redirect_uri: