Minimize webview using shared mechanism. (#37 #28)

This commit is contained in:
Ian Walton 2020-03-31 19:03:39 -04:00
parent 23c1cebb0b
commit eb9318383b
5 changed files with 27 additions and 12 deletions

View File

@ -30,6 +30,10 @@ class DisplayMirror(object):
def __init__(self):
self.open_player_menu = lambda: None
self.webview = None
def get_webview(self):
return self.webview
def run(self):
# Webview needs to be run in the MainThread.
@ -41,10 +45,11 @@ class DisplayMirror(object):
if 'webview_ready' in dir(webview):
threading.Thread(target=lambda: (webview.webview_ready(), load_idle())).start()
maybe_display_window = webview.create_window(title="Jellyfin MPV Shim Mirror", js_api=helpers, fullscreen=True)
if maybe_display_window is not None:
window = webview.create_window(title="Jellyfin MPV Shim Mirror", js_api=helpers, fullscreen=True)
if window is not None:
# It returned a Window object instead of blocking, we're running on 3.2 (or compatible)
self.display_window = maybe_display_window
self.display_window = window
self.webview = window
# 3.2's .loaded event runs every time a new DOM is loaded as well, so not suitable for this purpose
# However, 3.2's load_html waits for the DOM to be ready, so we can completely skip waiting for that ourselves.

View File

@ -27,9 +27,11 @@ def main(desktop=False, cef=False):
mirror = None
use_gui = False
use_webview = desktop or settings.enable_desktop
get_webview = lambda: None
if use_webview:
from .webclient_view import WebviewClient
userInterface = WebviewClient(cef=cef)
get_webview = userInterface.get_webview
elif settings.enable_gui:
try:
from .gui_mgr import userInterface
@ -39,9 +41,10 @@ def main(desktop=False, cef=False):
except Exception:
log.warning("Cannot load GUI. Falling back to command line interface.", exc_info=1)
if settings.display_mirroring:
if settings.display_mirroring and not use_webview:
try:
from .display_mirror import mirror
get_webview = mirror.get_webview
except ImportError:
log.warning("Cannot load display mirror.", exc_info=1)
@ -58,6 +61,7 @@ def main(desktop=False, cef=False):
playerManager.timeline_trigger = timelineManager.trigger
actionThread.start()
playerManager.action_trigger = actionThread.trigger
playerManager.get_webview = get_webview
userInterface.open_player_menu = playerManager.menu.show_menu
eventHandler.mirror = mirror
userInterface.start()

View File

@ -87,6 +87,7 @@ class PlayerManager(object):
self._tl_lock = RLock()
self.last_update = Timer()
self._jf_settings = None
self.get_webview = lambda: None
if is_using_ext_mpv:
extra_options = {
@ -273,11 +274,11 @@ class PlayerManager(object):
self.configure_streams()
self.update_subtitle_visuals()
print(self.get_webview())
if (self.get_webview() is not None and
(settings.display_mirroring or settings.desktop_fullscreen)):
self.get_webview().hide()
if win_utils:
if settings.display_mirroring:
win_utils.mirror_act(False)
elif settings.desktop_fullscreen:
win_utils.mirror_act(False, "Jellyfin MPV Desktop")
win_utils.raise_mpv()
if offset is not None and offset > 0:
@ -526,10 +527,9 @@ class PlayerManager(object):
self.should_send_timeline = False
self._video.client.jellyfin.session_stop(self.get_timeline_options())
if win_utils and settings.display_mirroring:
win_utils.mirror_act(True)
elif win_utils and settings.desktop_fullscreen:
win_utils.mirror_act(True, "Jellyfin MPV Desktop")
if (self.get_webview() is not None and
(settings.display_mirroring or settings.desktop_fullscreen)):
self.get_webview().show()
def upd_player_hide(self):
self._player.keep_open = self._video.parent.has_next

View File

@ -103,6 +103,7 @@ class WebviewClient(object):
self.open_player_menu = lambda: None
self.server = Server()
self.cef = cef
self.webview = None
def start(self):
pass
@ -112,6 +113,9 @@ class WebviewClient(object):
if success:
loaded.set()
def get_webview(self):
return self.webview
def run(self):
self.server.start()
@ -166,6 +170,7 @@ class WebviewClient(object):
window = webview.create_window(url=url, title="Jellyfin MPV Desktop",
fullscreen=settings.desktop_fullscreen, **extra_options)
if window is not None:
self.webview = window
def handle_close():
x, y = window.x, window.y
# For some reason it seems like X and Y are swapped?

View File

@ -30,6 +30,7 @@ def mirror_act(state, name="Jellyfin MPV Shim Mirror"):
win32gui.EnumWindows(windowEnumerationHandler, top_windows)
for i in top_windows:
if name in i[1]:
print(i)
win32gui.ShowWindow(i[0], 9 if state else 6)
break