From 7bf1e0dbb2be70dda3e9ce7f3e6d416b236b41e7 Mon Sep 17 00:00:00 2001 From: suro Date: Tue, 21 Apr 2026 10:05:37 +0200 Subject: [PATCH] update --- AzA march 2026/aza_empfang_app.py | 124 +++++++++++++++++++++++++----- AzA march 2026/empfang_routes.py | 9 ++- 2 files changed, 110 insertions(+), 23 deletions(-) diff --git a/AzA march 2026/aza_empfang_app.py b/AzA march 2026/aza_empfang_app.py index 3cc9d3d..c1af7cc 100644 --- a/AzA march 2026/aza_empfang_app.py +++ b/AzA march 2026/aza_empfang_app.py @@ -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}") diff --git a/AzA march 2026/empfang_routes.py b/AzA march 2026/empfang_routes.py index d5aae8a..a0d1886 100644 --- a/AzA march 2026/empfang_routes.py +++ b/AzA march 2026/empfang_routes.py @@ -2196,7 +2196,12 @@ async def empfang_page(request: Request): if html_path.is_file(): return HTMLResponse( content=html_path.read_text(encoding="utf-8"), - headers={"Cache-Control": "no-cache, no-store, must-revalidate", - "Pragma": "no-cache", "Expires": "0"}, + headers={ + "Cache-Control": "no-cache, no-store, must-revalidate", + "Pragma": "no-cache", + "Expires": "0", + # Desktop-Huelle (iframe-Modus): erlaubt Einbettung aus pywebview/null-Origin + "Content-Security-Policy": "frame-ancestors *;", + }, ) return HTMLResponse(content="

empfang.html nicht gefunden

", status_code=404)