From 7d2f785a8d5179a29df84a5cab1dc4bbd95ac33b Mon Sep 17 00:00:00 2001 From: croneter Date: Mon, 26 Nov 2018 07:31:36 +0100 Subject: [PATCH] Move detection of context menu to main loop - One thread less! --- resources/lib/kodimonitor.py | 31 ------------------------------- resources/lib/service_entry.py | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index feb8cec3..f273b4d0 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -8,7 +8,6 @@ from logging import getLogger from json import loads import copy import xbmc -from xbmcgui import Window from .plex_db import PlexDB from . import kodi_db @@ -396,36 +395,6 @@ class KodiMonitor(xbmc.Monitor): LOG.debug('Set the player state: %s', status) -class SpecialMonitor(backgroundthread.KillableThread): - """ - Detect the resume dialog for widgets. - Could also be used to detect external players (see Emby implementation) - """ - def run(self): - LOG.info("----====# Starting Special Monitor #====----") - # "Start from beginning", "Play from beginning" - strings = (utils.try_encode(utils.lang(12021)), - utils.try_encode(utils.lang(12023))) - while not self.isCanceled(): - if xbmc.getCondVisibility('Window.IsVisible(DialogContextMenu.xml)'): - if xbmc.getInfoLabel('Control.GetLabel(1002)') in strings: - # Remember that the item IS indeed resumable - control = int(Window(10106).getFocusId()) - app.PLAYSTATE.resume_playback = True if control == 1001 else False - else: - # Different context menu is displayed - app.PLAYSTATE.resume_playback = False - if xbmc.getCondVisibility('Window.IsVisible(MyVideoNav.xml)'): - path = xbmc.getInfoLabel('container.folderpath') - if (isinstance(path, str) and - path.startswith('special://profile/playlists')): - pass - # TODO: start polling PMS for playlist changes - # Optionally: poll PMS continuously with custom intervall - app.APP.monitor.waitForAbort(0.2) - LOG.info("#====---- Special Monitor Stopped ----====#") - - def _playback_cleanup(ended=False): """ PKC cleanup after playback ends/is stopped. Pass ended=True if Kodi diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index 76687ba3..0f51491a 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, unicode_literals import logging import sys import xbmc +import xbmcgui from . import utils, clientinfo, timing from . import initialsetup, artwork @@ -30,6 +31,10 @@ WINDOW_PROPERTIES = ( "plex_authenticated", "plex_restricteduser", "plex_allows_mediaDeletion", "plex_command", "plex_result") +# "Start from beginning", "Play from beginning" +STRINGS = (utils.try_encode(utils.lang(12021)), + utils.try_encode(utils.lang(12023))) + class Service(): ws = None @@ -336,7 +341,6 @@ class Service(): self.alexa = websocket_client.Alexa_Websocket() self.sync = sync.Sync() self.plexcompanion = plex_companion.PlexCompanion() - self.specialmonitor = kodimonitor.SpecialMonitor() self.playback_starter = playback_starter.PlaybackStarter() self.playqueue = playqueue.PlayqueueMonitor() @@ -399,6 +403,17 @@ class Service(): 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 @@ -428,7 +443,6 @@ class Service(): continue elif not self.startup_completed: self.startup_completed = True - self.specialmonitor.start() self.ws.start() self.sync.start() self.plexcompanion.start()