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(desktop): bring a minimized maximized window back maximized
rubenluetke10-beep022d6c138833
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex 55ec2949d9..bf5ae70df2 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -797,6 +797,65 @@ def window_needs_restore(title: str) -> bool:return True+#: ``WINDOWPLACEMENT.flags``: a minimized window that comes back maximized.+_WPF_RESTORETOMAXIMIZED = 0x0002+++def _placement_restores_maximized(hwnd: int, user32: Any) -> bool:+ """Was this (minimized) window maximized before it was minimized?++ ``GetWindowPlacement`` keeps that in ``WPF_RESTORETOMAXIMIZED``. Unknown+ counts as "no", the old restore-to-normal behaviour.+ """+ try:+ import ctypes+ from ctypes import wintypes++ class _Placement(ctypes.Structure):+ _fields_ = [+ ("length", wintypes.UINT),+ ("flags", wintypes.UINT),+ ("showCmd", wintypes.UINT),+ ("ptMinPosition", wintypes.POINT),+ ("ptMaxPosition", wintypes.POINT),+ ("rcNormalPosition", wintypes.RECT),+ ]++ placement = _Placement()+ placement.length = ctypes.sizeof(_Placement)+ if not user32.GetWindowPlacement(hwnd, ctypes.byref(placement)):+ return False+ return bool(placement.flags & _WPF_RESTORETOMAXIMIZED)+ except Exception: # noqa: BLE001 - unknown placement: restore as before+ return False+++def window_restores_maximized(title: str) -> bool:+ """Whether the minimized window titled ``title`` was maximized before.++ pywebview's ``restore()`` sets the normal size, so a maximized window that+ was minimized came back small; such a window is restored by Win32+ ``SW_RESTORE`` alone (``_bring_window_to_front_by_title``), which returns+ it maximized. ``False`` off Windows and whenever it cannot be told.+ """+ if sys.platform != "win32":+ return False+ try:+ import ctypes+ from ctypes import wintypes++ user32 = ctypes.WinDLL("user32", use_last_error=True)+ user32.FindWindowW.restype = wintypes.HWND+ user32.IsIconic.argtypes = [wintypes.HWND]+ user32.IsIconic.restype = wintypes.BOOL+ hwnd = user32.FindWindowW(None, title)+ if not hwnd or not user32.IsIconic(hwnd):+ return False+ return _placement_restores_maximized(hwnd, user32)+ except Exception: # noqa: BLE001 - unknown state: restore as before+ return False++def _bring_window_to_front_by_title(title: str) -> bool:"""Win32 fallback for hidden/minimized pywebview windows.@@ -893,11 +952,16 @@ def _bring_window_to_front_by_title(title: str) -> bool:# Order matters: SHOW/RESTORE first, then move if needed, then# Foreground+Active for keyboard focus. A window that is already on# screen keeps its state: SHOWNORMAL/RESTORE would un-maximize it.- if was_minimized or offscreen_minimized or not user32.IsWindowVisible(hwnd):+ # A window minimized while maximized comes back maximized: SW_RESTORE+ # alone does that, SW_SHOWNORMAL and the move below would shrink it.+ to_maximized = was_minimized and _placement_restores_maximized(hwnd, user32)+ if to_maximized:+ user32.ShowWindow(hwnd, 9) # SW_RESTORE+ elif was_minimized or offscreen_minimized or not user32.IsWindowVisible(hwnd):user32.ShowWindow(hwnd, 1) # SW_SHOWNORMALuser32.ShowWindow(hwnd, 5) # SW_SHOWuser32.ShowWindow(hwnd, 9) # SW_RESTORE- if was_minimized or offscreen_minimized:+ if (was_minimized or offscreen_minimized) and not to_maximized:width = max(900, min(1600, rect.right - rect.left))height = max(600, min(1000, rect.bottom - rect.top))if width > 5000 or height > 5000:@@ -4952,8 +5016,9 @@ class DesktopApp:if self._window is None:return {"ok": False, "reason": "no_window"}needs_restore = window_needs_restore(WINDOW_TITLE)+ to_maximized = window_restores_maximized(WINDOW_TITLE)self._window.show()- if needs_restore:+ if needs_restore and not to_maximized:self._window.restore()self._window_visible = Truefocused = _bring_window_to_front_by_title(WINDOW_TITLE)@@ -6260,8 +6325,11 @@ class DesktopApp:# pywebview's restore() un-maximizes a visible window too; only a# minimized or hidden one needs it.needs_restore = window_needs_restore(WINDOW_TITLE)+ # A window minimized while maximized is restored by Win32 below,+ # which brings it back maximized; pywebview's restore would not.+ to_maximized = window_restores_maximized(WINDOW_TITLE)self._window.show()- if needs_restore:+ if needs_restore and not to_maximized:self._window.restore()self._window_visible = True_bring_window_to_front_by_title(WINDOW_TITLE)diff --git a/tests/unit/ui/test_desktop_show_window.py b/tests/unit/ui/test_desktop_show_window.pyindex b2c9b9eae7..da2f24f8d5 100644--- a/tests/unit/ui/test_desktop_show_window.py+++ b/tests/unit/ui/test_desktop_show_window.py@@ -121,6 +121,7 @@ async def test_focus_window_now_completes_the_visibility_dance(# A minimized window: the dance restores it. (The real probe would read# whatever Jarvis window happens to be open on the test machine.)monkeypatch.setattr("jarvis.ui.desktop_app.window_needs_restore", lambda _title: True)+ monkeypatch.setattr("jarvis.ui.desktop_app.window_restores_maximized", lambda _title: False)import asyncio@@ -146,6 +147,7 @@ def test_focus_window_now_keeps_a_maximized_window_maximized(app._restore_overlay_for_visible_window = lambda: None # type: ignore[method-assign] # noqa: SLF001monkeypatch.setattr("jarvis.ui.desktop_app._bring_window_to_front_by_title", lambda _t: True)monkeypatch.setattr("jarvis.ui.desktop_app.window_needs_restore", lambda _title: False)+ monkeypatch.setattr("jarvis.ui.desktop_app.window_restores_maximized", lambda _title: False)assert app._focus_window_now() == {"ok": True, "focused": True} # noqa: SLF001assert [name for name, _ in window.calls] == ["show"]@@ -156,6 +158,47 @@ def test_focus_window_now_keeps_a_maximized_window_maximized(assert [name for name, _ in window.calls] == ["show"]+def test_a_window_minimized_while_maximized_comes_back_maximized(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Live 2026-10-03 (video): Edit on the appshot card brought the minimized+ app back small. pywebview's restore() sets the normal size; Win32+ SW_RESTORE alone returns a window to the maximized state it left."""+ app = DesktopApp.__new__(DesktopApp)+ window = _RecordingWindow()+ app._window = window # noqa: SLF001+ app._restore_overlay_for_visible_window = lambda: None # type: ignore[method-assign] # noqa: SLF001+ app._reload_window_if_stale = lambda: None # type: ignore[method-assign] # noqa: SLF001+ monkeypatch.setattr("jarvis.ui.desktop_app._bring_window_to_front_by_title", lambda _t: True)+ monkeypatch.setattr("jarvis.ui.desktop_app.window_needs_restore", lambda _title: True)+ monkeypatch.setattr("jarvis.ui.desktop_app.window_restores_maximized", lambda _title: True)++ assert app._focus_window_now() == {"ok": True, "focused": True} # noqa: SLF001+ app._safe_window_show() # noqa: SLF001+ assert "restore" not in [name for name, _ in window.calls]+++class _PlacementUser32:+ """Answers GetWindowPlacement with the given flags."""++ def __init__(self, flags: int, ok: bool = True) -> None:+ self.flags = flags+ self.ok = ok++ def GetWindowPlacement(self, _hwnd: int, placement: object) -> bool: # noqa: N802+ placement._obj.flags = self.flags # type: ignore[attr-defined]+ return self.ok+++def test_placement_tells_a_window_that_returns_maximized() -> None:+ from jarvis.ui.desktop_app import _placement_restores_maximized++ assert _placement_restores_maximized(1, _PlacementUser32(0x0002)) is True+ assert _placement_restores_maximized(1, _PlacementUser32(0x0000)) is False+ assert _placement_restores_maximized(1, _PlacementUser32(0x0002, ok=False)) is False+ assert _placement_restores_maximized(1, object()) is False++def test_focus_window_now_without_window_reports_no_window() -> None:app = DesktopApp.__new__(DesktopApp)app._window = None # noqa: SLF001