Do not delay a browser restart without a screen; clearer reload error
Without a connected monitor every Chromium start waited 30 s for one, so DevTools was unreachable for ~35 s after a restart. Only wait right after boot. The reload error now says Chromium may still be starting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b790f57531
commit
7e07428a81
3 files changed
+30
-5
No files matched your search
@@ -19,7 +19,7 @@ from pathlib import Path
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
from . import logutil
|
from . import logutil, sysinfo
|
||||||
from .config import load_config
|
from .config import load_config
|
||||||
from .paths import Paths, load_paths
|
from .paths import Paths, load_paths
|
||||||
from .validation import parse_resolution
|
from .validation import parse_resolution
|
||||||
@@ -153,15 +153,21 @@ def wait_for_x(timeout: float = 60) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
BOOT_GRACE_SECONDS = 180
|
||||||
|
|
||||||
|
|
||||||
def prepare_display(paths: Paths, config: dict[str, Any]) -> tuple[int, int] | None:
|
def prepare_display(paths: Paths, config: dict[str, Any]) -> tuple[int, int] | None:
|
||||||
outputs: list[dict[str, Any]] = []
|
outputs: list[dict[str, Any]] = []
|
||||||
# A monitor that powers up after the Pi may need a moment to report itself.
|
# A monitor that powers up together with the Pi may need a moment to report
|
||||||
for _ in range(15):
|
# itself. Later starts (a browser restart without a screen) should not wait.
|
||||||
|
attempts = 15 if (sysinfo.uptime_seconds() or 0) < BOOT_GRACE_SECONDS else 1
|
||||||
|
for attempt in range(attempts):
|
||||||
|
if attempt:
|
||||||
|
time.sleep(2)
|
||||||
proc = _run(["xrandr", "--query"])
|
proc = _run(["xrandr", "--query"])
|
||||||
outputs = parse_xrandr(proc.stdout) if proc and proc.returncode == 0 else []
|
outputs = parse_xrandr(proc.stdout) if proc and proc.returncode == 0 else []
|
||||||
if outputs:
|
if outputs:
|
||||||
break
|
break
|
||||||
time.sleep(2)
|
|
||||||
size = None
|
size = None
|
||||||
if outputs:
|
if outputs:
|
||||||
output = outputs[0]
|
output = outputs[0]
|
||||||
|
|||||||
@@ -357,7 +357,12 @@ def kiosk_reload():
|
|||||||
audit("page_reload")
|
audit("page_reload")
|
||||||
return _action_response(True, "De pagina wordt herladen.", request.referrer or url_for("ui.dashboard"))
|
return _action_response(True, "De pagina wordt herladen.", request.referrer or url_for("ui.dashboard"))
|
||||||
except CDPError as exc:
|
except CDPError as exc:
|
||||||
return _action_response(False, f"Herladen mislukt: {exc}", request.referrer or url_for("ui.dashboard"))
|
current_app.logger.warning("Herladen mislukt: %s", exc)
|
||||||
|
return _action_response(
|
||||||
|
False,
|
||||||
|
"Herladen mislukt: Chromium reageert niet. Als hij net (her)start, probeer het over een halve minuut opnieuw.",
|
||||||
|
request.referrer or url_for("ui.dashboard"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _helper_action(event: str, verb: str, *args: str, back: str):
|
def _helper_action(event: str, verb: str, *args: str, back: str):
|
||||||
|
|||||||
@@ -78,3 +78,17 @@ def test_local_pages_exist():
|
|||||||
www = Path(__file__).resolve().parents[1] / "www"
|
www = Path(__file__).resolve().parents[1] / "www"
|
||||||
for page in ("start.html", "offline.html", "setup.html", "kiosk.css", "logo.svg"):
|
for page in ("start.html", "offline.html", "setup.html", "kiosk.css", "logo.svg"):
|
||||||
assert (www / page).exists()
|
assert (www / page).exists()
|
||||||
|
|
||||||
|
|
||||||
|
def test_prepare_display_waits_for_a_screen_only_after_boot(paths, monkeypatch):
|
||||||
|
calls = []
|
||||||
|
monkeypatch.setattr(b, "_run", lambda args: calls.append(args) or None)
|
||||||
|
monkeypatch.setattr(b.time, "sleep", lambda s: None)
|
||||||
|
monkeypatch.setattr(b.sysinfo, "uptime_seconds", lambda: 3600.0)
|
||||||
|
assert b.prepare_display(paths, dict(DEFAULTS)) is None
|
||||||
|
assert sum(c == ["xrandr", "--query"] for c in calls) == 1
|
||||||
|
|
||||||
|
calls.clear()
|
||||||
|
monkeypatch.setattr(b.sysinfo, "uptime_seconds", lambda: 40.0)
|
||||||
|
b.prepare_display(paths, dict(DEFAULTS))
|
||||||
|
assert sum(c == ["xrandr", "--query"] for c in calls) == 15
|
||||||
Reference in new issue
Block a user