From a9ff70fac7e45cbaae85afe46382d635a5942f5a Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 22 Feb 2019 07:51:27 +0100 Subject: [PATCH] Fix PKC not exiting correctly due to a call to xbmc.getCondVisibility --- resources/lib/kodimonitor.py | 41 +++++++++++++++++++++++++++++++--- resources/lib/service_entry.py | 20 ++++------------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 16d3da98..d27fb696 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -7,7 +7,9 @@ from __future__ import absolute_import, division, unicode_literals from logging import getLogger from json import loads import copy + import xbmc +import xbmcgui from .plex_db import PlexDB from . import kodi_db @@ -16,11 +18,11 @@ from . import utils, timing, plex_functions as PF, playback from . import json_rpc as js, playqueue as PQ, playlist_func as PL from . import backgroundthread, app, variables as v -############################################################################### - LOG = getLogger('PLEX.kodimonitor') -############################################################################### +# "Start from beginning", "Play from beginning" +STRINGS = (utils.try_encode(utils.lang(12021)), + utils.try_encode(utils.lang(12023))) class KodiMonitor(xbmc.Monitor): @@ -530,3 +532,36 @@ def _clean_file_table(): LOG.debug('Database was locked, unable to clean file table') else: LOG.debug('Done cleaning up Kodi file table') + + +class ContextMonitor(backgroundthread.KillableThread): + """ + Detect the resume dialog for widgets. Could also be used to detect + external players (see Emby implementation) + + Let's not register this thread because it won't quit due to + xbmc.getCondVisibility + It should still exit at some point due to xbmc.abortRequested + """ + def run(self): + LOG.info("----===## Starting ContextMonitor ##===----") + # app.APP.register_thread(self) + try: + self._run() + finally: + # app.APP.deregister_thread(self) + LOG.info("##===---- ContextMonitor Stopped ----===##") + + def _run(self): + while not self.isCanceled(): + # The following function will block if called while PKC should + # exit! + if xbmc.getCondVisibility('Window.IsVisible(DialogContextMenu.xml)'): + if xbmc.getInfoLabel('Control.GetLabel(1002)') in STRINGS: + # Remember that the item IS indeed resumable + control = int(xbmcgui.Window(10106).getFocusId()) + app.PLAYSTATE.resume_playback = True if control == 1001 else False + else: + # Different context menu is displayed + app.PLAYSTATE.resume_playback = False + app.APP.monitor.waitForAbort(0.1) diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index 1e0831f2..7169d0c0 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -4,7 +4,6 @@ from __future__ import absolute_import, division, unicode_literals import logging import sys import xbmc -import xbmcgui from . import utils, clientinfo, timing from . import initialsetup @@ -30,10 +29,6 @@ WINDOW_PROPERTIES = ( "pms_token", "plex_token", "plex_authenticated", "plex_restricteduser", "plex_allows_mediaDeletion", "plexkodiconnect.command", "plex_result") -# "Start from beginning", "Play from beginning" -STRINGS = (utils.try_encode(utils.lang(12021)), - utils.try_encode(utils.lang(12023))) - class Service(object): ws = None @@ -105,6 +100,7 @@ class Service(object): self.setup = None self.alexa = None self.playqueue = None + self.context_monitor = None # Flags for other threads self.connection_check_running = False self.auth_running = False @@ -402,6 +398,9 @@ class Service(object): # Some plumbing app.init() app.APP.monitor = kodimonitor.KodiMonitor() + self.context_monitor = kodimonitor.ContextMonitor() + # Start immediately to catch user input even before auth + self.context_monitor.start() app.APP.player = xbmc.Player() # Initialize the PKC playqueues PQ.init_playqueues() @@ -467,17 +466,6 @@ class Service(object): app.APP.monitor.waitForAbort(0.1) continue - # Detect the resume dialog for widgets. Could also be used to detect - # external players (see Emby implementation) - if xbmc.getCondVisibility('Window.IsVisible(DialogContextMenu.xml)'): - if xbmc.getInfoLabel('Control.GetLabel(1002)') in STRINGS: - # Remember that the item IS indeed resumable - control = int(xbmcgui.Window(10106).getFocusId()) - app.PLAYSTATE.resume_playback = True if control == 1001 else False - else: - # Different context menu is displayed - app.PLAYSTATE.resume_playback = False - # Before proceeding, need to make sure: # 1. Server is online # 2. User is set