update
This commit is contained in:
@@ -2,7 +2,12 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
AZA Empfang - Schlanke Desktop-Huelle fuer die Empfangs-Weboberflaeche.
|
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
|
import json
|
||||||
@@ -91,7 +96,8 @@ class _Api:
|
|||||||
"error": "Server nicht erreichbar. Bitte Netzwerk pruefen."}
|
"error": "Server nicht erreichbar. Bitte Netzwerk pruefen."}
|
||||||
|
|
||||||
def open_in_browser(self):
|
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):
|
def toggle_on_top(self):
|
||||||
if not self._pin_lock.acquire(blocking=False):
|
if not self._pin_lock.acquire(blocking=False):
|
||||||
@@ -303,9 +309,17 @@ def main():
|
|||||||
print("FEHLER: pywebview ist nicht installiert.")
|
print("FEHLER: pywebview ist nicht installiert.")
|
||||||
print("Bitte ausfuehren: pip install pywebview")
|
print("Bitte ausfuehren: pip install pywebview")
|
||||||
sys.exit(1)
|
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()
|
settings = _load_settings()
|
||||||
url = _empfang_url()
|
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))
|
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))
|
h = max(_MIN_SIZE[1], min(1200, settings.get("height") or _DEFAULT_H))
|
||||||
@@ -317,29 +331,89 @@ def main():
|
|||||||
else:
|
else:
|
||||||
x, y = None, None
|
x, y = None, None
|
||||||
|
|
||||||
window = webview.create_window(
|
on_top = bool(settings.get("on_top", False))
|
||||||
_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",
|
|
||||||
)
|
|
||||||
|
|
||||||
api = _Api(window, settings.get("on_top", False), url)
|
if use_iframe_shell:
|
||||||
window.expose(api.check_url, api.open_in_browser,
|
window = webview.create_window(
|
||||||
api.toggle_on_top, api.get_on_top,
|
_APP_TITLE,
|
||||||
api.get_version, api.get_url, api.get_public_url)
|
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():
|
def _on_closing():
|
||||||
try:
|
try:
|
||||||
_save_settings({
|
_save_settings({
|
||||||
"x": window.x, "y": window.y,
|
"x": window.x,
|
||||||
"width": window.width, "height": window.height,
|
"y": window.y,
|
||||||
|
"width": window.width,
|
||||||
|
"height": window.height,
|
||||||
"on_top": api._on_top,
|
"on_top": api._on_top,
|
||||||
})
|
})
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -352,7 +426,15 @@ def main():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
print(f"[AZA Empfang] Fehler: {e}")
|
print(f"[AZA Empfang] Fehler: {e}")
|
||||||
|
|
||||||
|
|||||||
@@ -2196,7 +2196,12 @@ async def empfang_page(request: Request):
|
|||||||
if html_path.is_file():
|
if html_path.is_file():
|
||||||
return HTMLResponse(
|
return HTMLResponse(
|
||||||
content=html_path.read_text(encoding="utf-8"),
|
content=html_path.read_text(encoding="utf-8"),
|
||||||
headers={"Cache-Control": "no-cache, no-store, must-revalidate",
|
headers={
|
||||||
"Pragma": "no-cache", "Expires": "0"},
|
"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="<h1>empfang.html nicht gefunden</h1>", status_code=404)
|
return HTMLResponse(content="<h1>empfang.html nicht gefunden</h1>", status_code=404)
|
||||||
|
|||||||
Reference in New Issue
Block a user