Skip to content

Commit

Permalink
Wait until the server is ready before launching webview.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwalton3 committed Mar 30, 2020
1 parent e410d1a commit 8c4844c
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jellyfin_mpv_shim/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME = 'jellyfin-mpv-shim'
USER_APP_NAME = 'Jellyfin MPV Shim'
CLIENT_VERSION = "1.5.1"
CLIENT_VERSION = "1.5.2"
USER_AGENT = "Jellyfin-MPV-Shim/%s" % CLIENT_VERSION
14 changes: 12 additions & 2 deletions jellyfin_mpv_shim/webclient_view/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import threading
import importlib.resources
import urllib.request
from datetime import date
from werkzeug.serving import make_server
from flask import Flask, request, jsonify
from time import sleep

# So, most of my use of the webview library is ugly but there's a reason for this!
# Debian's python3-webview package is super old (2.3), pip3's pywebview package is much newer (3.2).
@@ -38,7 +40,6 @@ def run(self):
with importlib.resources.path(__package__, 'webclient') as static_wc:
app = Flask(__name__, static_url_path='',
static_folder=static_wc)

@app.after_request
def add_header(response):
if request.path == "/index.html":
@@ -124,8 +125,17 @@ def override_gtk(self, webview, status):
qt.BrowserView.on_load_finished = lambda self: None
except Exception: pass

url = "http://127.0.0.1:18096/index.html"
# Wait until the server is ready.
while True:
try:
urllib.request.urlopen(url)
break
except Exception: pass
sleep(0.1)

# Webview needs to be run in the MainThread.
maybe_display_window = webview.create_window(url="http://127.0.0.1:18096/index.html", title="Jellyfin MPV Shim")
maybe_display_window = webview.create_window(url=url, title="Jellyfin MPV Shim")
if maybe_display_window is not None:
webview.start()
self.server.stop()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

setup(
name='jellyfin-mpv-shim',
version='1.5.1',
version='1.5.2',
author="Ian Walton",
author_email="iwalton3@gmail.com",
description="Cast media from Jellyfin Mobile and Web apps to MPV. (Unofficial)",

0 comments on commit 8c4844c

Please sign in to comment.