Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(ui): claim DPI awareness before any window so the bar can't shrink mid-session
Ruben Lütke82fd0d1e46a0
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex d34d8442bd..eca3716a6c 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -47,6 +47,49 @@ if TYPE_CHECKING:from jarvis.ui.web.server import WebServer+def _claim_system_dpi_awareness() -> None:+ """Claim SYSTEM DPI awareness for the process BEFORE any window exists.++ Root cause of the recurring "JarvisBar shrank and jumped, only a restart+ fixes it" bug: the always-on bar's Tk window is built (in the backend+ thread) while the process is still DPI-UNAWARE, so Windows bitmap-upscales+ it to a normal physical size and everything looks fine. Then pywebview's+ ``webview.start()`` calls ``user32.SetProcessDPIAware()`` deep inside its+ winforms backend — flipping the process to SYSTEM-aware AT RUNTIME instantly+ strips the DPI virtualization off every EXISTING window, so the bar snaps+ from its upscaled size to raw pixels (~2/3 size on a 150% display) and jumps+ position. Verified live: an unaware-created 107x48 window sits at 161x72+ physical; the moment ``SetProcessDPIAware()`` runs it becomes 107x48.++ Claiming awareness HERE — at desktop_app import, before the backend thread+ builds the bar and before the webview starts — makes pywebview's later call+ a no-op, so no window is ever created in the soon-to-flip unaware state and+ nothing shrinks mid-session. We deliberately use the SAME level pywebview+ uses (SYSTEM via the legacy ``SetProcessDPIAware``, NOT per-monitor), so the+ main window's own sizing math is unchanged — this only fixes the boot-order+ race, it does not alter the steady-state awareness the app has always run+ at. Idempotent (first-writer-wins at the Win32 level); guarded so a failure+ never blocks boot; a plain no-op off Windows.++ The bar then renders at the correct physical size via+ ``jarvisbar.overlay._display_scale`` (Tk reports the true 144 dpi once the+ process is aware before ``tk.Tk()``).+ """+ if sys.platform != "win32":+ return+ try:+ import ctypes++ ctypes.windll.user32.SetProcessDPIAware()+ except Exception: # noqa: BLE001,S110 — never block boot on a DPI hiccup+ pass+++# Claim DPI awareness at import time — runs before ``DesktopApp`` is ever+# instantiated, so before the overlay bar and the pywebview window both exist.+_claim_system_dpi_awareness()++# ---------------------------------------------------------------------------# Konstanten# ---------------------------------------------------------------------------diff --git a/tests/unit/ui/test_desktop_dpi_early_claim.py b/tests/unit/ui/test_desktop_dpi_early_claim.pynew file mode 100644index 0000000000..fca742d277--- /dev/null+++ b/tests/unit/ui/test_desktop_dpi_early_claim.py@@ -0,0 +1,55 @@+"""The desktop process claims DPI awareness BEFORE any window is created.++Regression guard for the recurring "JarvisBar shrank and jumped mid-session,+only a restart fixes it" bug. Root cause: the always-on bar's Tk window is built+(backend thread) while the process is still DPI-UNAWARE, so Windows upscales it+to a normal size; then pywebview's ``webview.start()`` calls+``SetProcessDPIAware()`` at RUNTIME, which strips that virtualization off the+already-existing window and it snaps to raw pixels. Claiming SYSTEM awareness at+desktop_app import — before the backend thread and the webview — makes+pywebview's later call a no-op, so the flip can never happen. This test fails if+that early claim is ever removed (e.g. clobbered by a consolidate snapshot).+"""+from __future__ import annotations++import ctypes+import types++import jarvis.ui.desktop_app as da+++def test_claims_system_dpi_awareness_on_win32(monkeypatch):+ calls: list[str] = []+ fake_windll = types.SimpleNamespace(+ user32=types.SimpleNamespace(SetProcessDPIAware=lambda: calls.append("set"))+ )+ monkeypatch.setattr(da.sys, "platform", "win32")+ monkeypatch.setattr(ctypes, "windll", fake_windll, raising=False)++ da._claim_system_dpi_awareness()++ assert calls == ["set"], (+ "the process must claim SYSTEM DPI awareness up front — else the bar is "+ "created unaware and pywebview's later flip shrinks + moves it"+ )+++def test_dpi_claim_is_noop_off_windows(monkeypatch):+ # Cross-platform: off Windows there is no ``ctypes.windll`` — the claim must+ # return before touching it and must never raise.+ monkeypatch.setattr(da.sys, "platform", "linux")+ da._claim_system_dpi_awareness()+++def test_dpi_claim_swallows_failure(monkeypatch):+ def _boom() -> None:+ raise OSError("no user32 here")++ fake_windll = types.SimpleNamespace(+ user32=types.SimpleNamespace(SetProcessDPIAware=_boom)+ )+ monkeypatch.setattr(da.sys, "platform", "win32")+ monkeypatch.setattr(ctypes, "windll", fake_windll, raising=False)++ # Guarded — a DPI hiccup must never block boot.+ da._claim_system_dpi_awareness()