Move detection of context menu to main loop

- One thread less!
This commit is contained in:
croneter 2018-11-26 07:31:36 +01:00
parent c4156cb865
commit 7d2f785a8d
2 changed files with 16 additions and 33 deletions

View file

@ -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

View file

@ -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()