add context monitor to replace default context menu with EmbyCon menu

This commit is contained in:
faush01
2018-07-14 13:37:38 +10:00
parent 205160f363
commit fd86bdb526
5 changed files with 67 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.embycon"
name="EmbyCon"
version="1.5.27"
version="1.5.28"
provider-name="Team B">
<requires>
<import addon="xbmc.python" version="2.25.0"/>

View File

@@ -732,4 +732,8 @@ msgstr ""
msgctxt "#30333"
msgid "Cache artwork in the background"
msgstr ""
msgstr ""
msgctxt "#30334"
msgid "Override default context menu"
msgstr ""

View File

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

View File

@@ -57,6 +57,7 @@
<setting id="moviePageSize" type="slider" label="30331" default="0" range="0,1,100" option="int" visible="true"/>
<setting id="show_x_filtered_items" type="slider" label="30018" default="20" range="5,1,100" option="int" visible="true"/>
<setting id="show_latest_unplayed" type="bool" label="30027" default="false" visible="true" enable="true" />
<setting id="override_contextmenu" type="bool" label="30334" default="true" visible="true"/>
<setting id="widget_select_action" type="select" label="30026" lvalues="30313|30314" default="0" visible="true"/>
<setting id="episode_name_format" type="select" label="30019" default="{ItemName}" values="{ItemName}|s{SeasonIndex}e{EpisodeIndex} - {ItemName}|{SeriesName} - s{SeasonIndex}e{EpisodeIndex} - {ItemName}" />
</category>

View File

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