def run(self): # Webview needs to be run in the MainThread. # Prepare for version 2.3 before calling create_window(), which might block forever. self.display_window = webview # Since webview.create_window might take exclusive and permanent lock on the main thread, # we need to start this wait_load function before we start webview itself. if "webview_ready" in dir(webview): threading.Thread( target=lambda: (webview.webview_ready(), load_idle()) ).start() 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 = 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. threading.Thread(target=load_idle).start() webview.start()
def get_cookies(): timeout = 120 def is_logged_in(): return webview.evaluate_js( "document.querySelector('#logout-btn') !== null") while not webview.webview_ready() or not is_logged_in(): time.sleep(1) timeout -= 1 if timeout == 0: raise AuthenticationFailed("Can't login, timeout exceeded.") if not webview.window_exists(): raise AuthenticationFailed( "Webview window closed prematurely.") cookies = webview.evaluate_js("document.cookie") webview.destroy_window() return cookies
def _no_resize(webview): assert webview.webview_ready(10) destroy_event.set()
def bg_color(): child_window = webview.create_window('Window #2', background_color='#0000FF') assert child_window != 'MainWindow' webview.webview_ready() webview.destroy_window(child_window)
def _bg_color(webview): child_window = webview.create_window('Window #2', background_color='#0000FF') webview.webview_ready() webview.destroy_window(child_window) destroy_event.set()
def _fullscreen(webview): assert webview.webview_ready(10) destroy_event.set()
def _localization(webview): assert webview.webview_ready(10) destroy_event.set()
def _simple_browser(webview): assert webview.webview_ready(10) destroy_event.set()