diff --git a/addon.xml b/addon.xml index 06adfa8..d5f392a 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 0f8ffd9..6b956fe 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -732,4 +732,8 @@ msgstr "" msgctxt "#30333" msgid "Cache artwork in the background" -msgstr "" \ No newline at end of file +msgstr "" + +msgctxt "#30334" +msgid "Override default context menu" +msgstr "" diff --git a/resources/lib/context_monitor.py b/resources/lib/context_monitor.py new file mode 100644 index 0000000..d541ec0 --- /dev/null +++ b/resources/lib/context_monitor.py @@ -0,0 +1,46 @@ +import threading +import sys +import xbmc +import xbmcgui + +from simple_logging import SimpleLogging +from resources.lib.functions import show_menu + +log = SimpleLogging(__name__) + + +class ContextMonitor(threading.Thread): + + stop_monitor = False + + def run(self): + + #condition_command = "(Window.IsVisible(DialogContextMenu.xml) + !String.IsEmpty(ListItem.Property(id)) + String.StartsWith(ListItem.Path,plugin://plugin.video.embycon))" + condition_command = ("Window.IsVisible(DialogContextMenu.xml) + " + + "[Window.IsActive(Home) | " + + "[!String.IsEmpty(ListItem.Property(id) + " + + "String.StartsWith(ListItem.Path,plugin://plugin.video.embycon)]]") + + monitor = xbmc.Monitor() + log.debug("ContextMonitor Thread Started") + + while not xbmc.abortRequested: + + if xbmc.getCondVisibility(condition_command): + log.debug("ContextMonitor Found Context Menu!!!!!!") + xbmc.executebuiltin("Dialog.Close(contextmenu, true)") + + item_id = xbmc.getInfoLabel('ListItem.Property(id)') + if item_id: + log.debug("ContextMonitor Item ID: {0}", item_id) + params = {} + params["item_id"] = item_id + show_menu(params) + + xbmc.sleep(200) + + log.debug("ContextMonitor Thread Exited") + + def stop_monitor(self): + log.debug("ContextMonitor Stop Called") + self.stop_monitor = True diff --git a/resources/settings.xml b/resources/settings.xml index 41025e9..d3545a5 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -57,6 +57,7 @@ + diff --git a/service.py b/service.py index 1c61a5c..fb06b1b 100644 --- a/service.py +++ b/service.py @@ -18,6 +18,7 @@ from resources.lib.kodi_utils import HomeWindow from resources.lib.widgets import checkForNewContent, set_background_image from resources.lib.websocket_client import WebSocketClient from resources.lib.menu_functions import set_library_window_values +from resources.lib.context_monitor import ContextMonitor # clear user and token when logging in home_window = HomeWindow() @@ -49,12 +50,21 @@ websocket_client = WebSocketClient() # TODO: this is used to append to the end of PLAY urls, this is to stop mark watched from overriding the Emby ones home_window.setProperty("session_id", str(time.time())) + + # start the WebSocket Client running settings = xbmcaddon.Addon() remote_control = settings.getSetting('remoteControl') == "true" if remote_control: websocket_client.start() +# Start the context menu monitor +context_monitor = None +context_menu = settings.getSetting('override_contextmenu') == "true" +if context_menu: + context_monitor = ContextMonitor() + context_monitor.start() + # monitor.abortRequested() is causes issues, it currently triggers for all addon cancelations which causes # the service to exit when a user cancels an addon load action. This is a bug in Kodi. # I am switching back to xbmc.abortRequested approach until kodi is fixed or I find a work arround @@ -90,6 +100,10 @@ while not xbmc.abortRequested: xbmc.sleep(1000) +# call stop on the context menu monitor +if context_monitor: + context_monitor.stop_monitor() + # stop the WebSocket Client websocket_client.stop_client()