update
This commit is contained in:
@@ -2,7 +2,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
AZA Empfang - Schlanke Desktop-Huelle fuer die Empfangs-Weboberflaeche.
|
||||
Laedt die Empfangs-Seite in einem WebView-Fenster.
|
||||
|
||||
Standard: Laedt die Empfang-URL direkt im Fenster (kein iframe) — zuverlaessig
|
||||
mit Edge WebView2 unter Windows.
|
||||
|
||||
Optional: Umgebungsvariable AZA_EMPFANG_IFRAME=1 aktiviert die alte iframe-Huelle
|
||||
(Toolbar in HTML); dazu sollte der Server frame-embedding erlauben.
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -91,7 +96,8 @@ class _Api:
|
||||
"error": "Server nicht erreichbar. Bitte Netzwerk pruefen."}
|
||||
|
||||
def open_in_browser(self):
|
||||
webbrowser.open(_PUBLIC_EMPFANG_URL)
|
||||
"""Öffnet dieselbe Ziel-URL wie im Fenster (lokal oder Produktion)."""
|
||||
webbrowser.open(self._url)
|
||||
|
||||
def toggle_on_top(self):
|
||||
if not self._pin_lock.acquire(blocking=False):
|
||||
@@ -303,9 +309,17 @@ def main():
|
||||
print("FEHLER: pywebview ist nicht installiert.")
|
||||
print("Bitte ausfuehren: pip install pywebview")
|
||||
sys.exit(1)
|
||||
try:
|
||||
from webview.menu import Menu, MenuAction, MenuSeparator
|
||||
except ImportError:
|
||||
Menu = None # type: ignore
|
||||
MenuAction = None # type: ignore
|
||||
MenuSeparator = None # type: ignore
|
||||
|
||||
settings = _load_settings()
|
||||
url = _empfang_url()
|
||||
# iframe-Huelle (alt): nur setzen wenn noetig: AZA_EMPFANG_IFRAME=1
|
||||
use_iframe_shell = os.environ.get("AZA_EMPFANG_IFRAME", "").strip() == "1"
|
||||
|
||||
w = max(_MIN_SIZE[0], min(1920, settings.get("width") or _DEFAULT_W))
|
||||
h = max(_MIN_SIZE[1], min(1200, settings.get("height") or _DEFAULT_H))
|
||||
@@ -317,29 +331,89 @@ def main():
|
||||
else:
|
||||
x, y = None, None
|
||||
|
||||
window = webview.create_window(
|
||||
_APP_TITLE,
|
||||
html=_SHELL_HTML,
|
||||
width=w,
|
||||
height=h,
|
||||
x=x,
|
||||
y=y,
|
||||
min_size=_MIN_SIZE,
|
||||
on_top=settings.get("on_top", False),
|
||||
text_select=True,
|
||||
background_color="#f0f4f8",
|
||||
)
|
||||
on_top = bool(settings.get("on_top", False))
|
||||
|
||||
api = _Api(window, settings.get("on_top", False), url)
|
||||
window.expose(api.check_url, api.open_in_browser,
|
||||
api.toggle_on_top, api.get_on_top,
|
||||
api.get_version, api.get_url, api.get_public_url)
|
||||
if use_iframe_shell:
|
||||
window = webview.create_window(
|
||||
_APP_TITLE,
|
||||
html=_SHELL_HTML,
|
||||
width=w,
|
||||
height=h,
|
||||
x=x,
|
||||
y=y,
|
||||
min_size=_MIN_SIZE,
|
||||
on_top=on_top,
|
||||
text_select=True,
|
||||
background_color="#f0f4f8",
|
||||
)
|
||||
api = _Api(window, on_top, url)
|
||||
window.expose(
|
||||
api.check_url,
|
||||
api.open_in_browser,
|
||||
api.toggle_on_top,
|
||||
api.get_on_top,
|
||||
api.get_version,
|
||||
api.get_url,
|
||||
api.get_public_url,
|
||||
)
|
||||
else:
|
||||
window = webview.create_window(
|
||||
_APP_TITLE,
|
||||
url=url,
|
||||
width=w,
|
||||
height=h,
|
||||
x=x,
|
||||
y=y,
|
||||
min_size=_MIN_SIZE,
|
||||
on_top=on_top,
|
||||
text_select=True,
|
||||
background_color="#f0f4f8",
|
||||
)
|
||||
api = _Api(window, on_top, url)
|
||||
|
||||
def _reload():
|
||||
try:
|
||||
window.evaluate_js("window.location.reload()")
|
||||
except Exception as exc:
|
||||
print(f"[AZA Empfang] Neu laden: {exc}")
|
||||
|
||||
def _info_box():
|
||||
try:
|
||||
msg = f"{api.get_version()}\n\n{api._url}"
|
||||
try:
|
||||
import ctypes
|
||||
|
||||
ctypes.windll.user32.MessageBoxW(0, msg, _APP_TITLE, 0)
|
||||
except Exception:
|
||||
print(msg)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _toggle_pin_menu():
|
||||
api.toggle_on_top()
|
||||
|
||||
menu = None
|
||||
if Menu is not None:
|
||||
menu = [
|
||||
Menu(
|
||||
"Empfang",
|
||||
[
|
||||
MenuAction("Neu laden", _reload),
|
||||
MenuAction("Im Browser \u00f6ffnen", api.open_in_browser),
|
||||
MenuAction("Immer im Vordergrund", _toggle_pin_menu),
|
||||
MenuSeparator(),
|
||||
MenuAction("Version / Info", _info_box),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
def _on_closing():
|
||||
try:
|
||||
_save_settings({
|
||||
"x": window.x, "y": window.y,
|
||||
"width": window.width, "height": window.height,
|
||||
"x": window.x,
|
||||
"y": window.y,
|
||||
"width": window.width,
|
||||
"height": window.height,
|
||||
"on_top": api._on_top,
|
||||
})
|
||||
except Exception:
|
||||
@@ -352,7 +426,15 @@ def main():
|
||||
pass
|
||||
|
||||
try:
|
||||
webview.start()
|
||||
if use_iframe_shell:
|
||||
webview.start()
|
||||
elif menu:
|
||||
try:
|
||||
webview.start(menu=menu)
|
||||
except TypeError:
|
||||
webview.start()
|
||||
else:
|
||||
webview.start()
|
||||
except Exception as e:
|
||||
print(f"[AZA Empfang] Fehler: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user