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 the window forward without un-maximizing it
rubenluetke10-beepd6a464153093
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex 78cbbcfbec..4ea0ed82ea 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -665,7 +665,12 @@ def _force_foreground_hwnd(hwnd: int, user32: Any, kernel32: Any) -> bool:the supported recovery. Every attachment is detached in ``finally`` so afailed focus attempt cannot poison keyboard routing."""- user32.ShowWindow(hwnd, 9) # SW_RESTORE+ # SW_RESTORE only for a minimized window: on a maximized one it means+ # "back to the normal size", which shrank the app every time something+ # merely asked to bring it forward (an appshot card click, 2026-10-03).+ restore = _is_minimized(hwnd, user32)+ if restore:+ user32.ShowWindow(hwnd, 9) # SW_RESTOREif user32.SetForegroundWindow(hwnd):user32.SetActiveWindow(hwnd)if user32.GetForegroundWindow() == hwnd:@@ -688,7 +693,8 @@ def _force_foreground_hwnd(hwnd: int, user32: Any, kernel32: Any) -> bool:):attached_target = bool(user32.AttachThreadInput(current_thread, target_thread, True))user32.BringWindowToTop(hwnd)- user32.ShowWindow(hwnd, 9) # SW_RESTORE+ if restore:+ user32.ShowWindow(hwnd, 9) # SW_RESTOREuser32.SetForegroundWindow(hwnd)user32.SetActiveWindow(hwnd)if user32.GetForegroundWindow() == hwnd:@@ -748,6 +754,45 @@ def _window_answers(hwnd: int, user32: Any, *, timeout_ms: int = _WINDOW_ANSWER_return True+def _is_minimized(hwnd: int, user32: Any) -> bool:+ """``IsIconic`` when the binding has it; an unknown state counts as minimized+ so the old restore-everything behaviour is the fallback, never a no-op."""+ probe = getattr(user32, "IsIconic", None)+ if probe is None:+ return True+ try:+ return bool(probe(hwnd))+ except Exception: # noqa: BLE001 - unreadable state: restore as before+ return True+++def window_needs_restore(title: str) -> bool:+ """Whether raising the window titled ``title`` must restore it first.++ ``True`` for a minimized or hidden window, and wherever it cannot be told+ (other OSes, no such window). ``False`` for a visible one — restoring+ that would turn a maximized window back into its smaller normal size.+ """+ if sys.platform != "win32":+ return True+ 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+ user32.IsWindowVisible.argtypes = [wintypes.HWND]+ user32.IsWindowVisible.restype = wintypes.BOOL+ hwnd = user32.FindWindowW(None, title)+ if not hwnd:+ return True+ return bool(user32.IsIconic(hwnd)) or not bool(user32.IsWindowVisible(hwnd))+ except Exception: # noqa: BLE001 - unknown state: restore as before+ return True++def _bring_window_to_front_by_title(title: str) -> bool:"""Win32 fallback for hidden/minimized pywebview windows.@@ -787,6 +832,8 @@ def _bring_window_to_front_by_title(title: str) -> bool:user32.GetWindowRect.argtypes = [wintypes.HWND, ctypes.POINTER(wintypes.RECT)]user32.IsIconic.argtypes = [wintypes.HWND]user32.IsIconic.restype = wintypes.BOOL+ user32.IsWindowVisible.argtypes = [wintypes.HWND]+ user32.IsWindowVisible.restype = wintypes.BOOLuser32.MoveWindow.argtypes = [wintypes.HWND,ctypes.c_int,@@ -840,10 +887,12 @@ def _bring_window_to_front_by_title(title: str) -> bool:offscreen_minimized = rect.left <= -30000 or rect.top <= -30000# Order matters: SHOW/RESTORE first, then move if needed, then- # Foreground+Active for keyboard focus.- user32.ShowWindow(hwnd, 1) # SW_SHOWNORMAL- user32.ShowWindow(hwnd, 5) # SW_SHOW- user32.ShowWindow(hwnd, 9) # SW_RESTORE+ # 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):+ user32.ShowWindow(hwnd, 1) # SW_SHOWNORMAL+ user32.ShowWindow(hwnd, 5) # SW_SHOW+ user32.ShowWindow(hwnd, 9) # SW_RESTOREif was_minimized or offscreen_minimized:width = max(900, min(1600, rect.right - rect.left))height = max(600, min(1000, rect.bottom - rect.top))@@ -4885,8 +4934,10 @@ class DesktopApp:self._ensure_main_window()if self._window is None:return {"ok": False, "reason": "no_window"}+ needs_restore = window_needs_restore(WINDOW_TITLE)self._window.show()- self._window.restore()+ if needs_restore:+ self._window.restore()self._window_visible = Truefocused = _bring_window_to_front_by_title(WINDOW_TITLE)# Restore the persistent bar if a prior minimise cleared it.@@ -6186,8 +6237,12 @@ class DesktopApp:self._ensure_main_window()returntry:+ # pywebview's restore() un-maximizes a visible window too; only a+ # minimized or hidden one needs it.+ needs_restore = window_needs_restore(WINDOW_TITLE)self._window.show()- self._window.restore()+ if needs_restore:+ self._window.restore()self._window_visible = True_bring_window_to_front_by_title(WINDOW_TITLE)self._reload_window_if_stale()diff --git a/tests/unit/ui/test_desktop_focus.py b/tests/unit/ui/test_desktop_focus.pyindex 9a5ae0d28b..934f21f870 100644--- a/tests/unit/ui/test_desktop_focus.py+++ b/tests/unit/ui/test_desktop_focus.py@@ -101,3 +101,32 @@ def test_foreground_lock_recovery_attaches_and_always_detaches() -> None:(10, 20, False),(10, 30, False),]+++class _ShowRecordingUser32(_User32):+ def __init__(self, *, iconic: bool) -> None:+ super().__init__()+ self.iconic = iconic+ self.shows: list[int] = []++ def ShowWindow(self, _hwnd: int, mode: int) -> bool:+ self.shows.append(mode)+ return True++ def IsIconic(self, _hwnd: int) -> bool:+ return self.iconic+++def test_raising_a_window_on_screen_never_restores_it() -> None:+ """SW_RESTORE un-maximizes a maximized window (appshot card click, 2026-10-03)."""+ user32 = _ShowRecordingUser32(iconic=False)++ assert _force_foreground_hwnd(200, user32, _Kernel32()) is True+ assert 9 not in user32.shows+++def test_raising_a_minimized_window_still_restores_it() -> None:+ user32 = _ShowRecordingUser32(iconic=True)++ assert _force_foreground_hwnd(200, user32, _Kernel32()) is True+ assert user32.shows.count(9) >= 1diff --git a/tests/unit/ui/test_desktop_show_window.py b/tests/unit/ui/test_desktop_show_window.pyindex de1d4defee..b2c9b9eae7 100644--- a/tests/unit/ui/test_desktop_show_window.py+++ b/tests/unit/ui/test_desktop_show_window.py@@ -118,6 +118,9 @@ async def test_focus_window_now_completes_the_visibility_dance("jarvis.ui.desktop_app._bring_window_to_front_by_title",lambda _title: True,)+ # 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)import asyncio@@ -131,6 +134,28 @@ async def test_focus_window_now_completes_the_visibility_dance(assert all(thread is not loop_thread for _, thread in window.calls)+def test_focus_window_now_keeps_a_maximized_window_maximized(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Live 2026-10-03: a click on the appshot card shrank the maximized app,+ because "bring it forward" also restored it — on Windows that means back+ to the normal size. A window already on screen is only raised."""+ 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+ 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: False)++ assert app._focus_window_now() == {"ok": True, "focused": True} # noqa: SLF001+ assert [name for name, _ in window.calls] == ["show"]++ window.calls.clear()+ app._reload_window_if_stale = lambda: None # type: ignore[method-assign] # noqa: SLF001+ app._safe_window_show() # noqa: SLF001 # the appshot card / overlay path+ assert [name for name, _ in window.calls] == ["show"]++def test_focus_window_now_without_window_reports_no_window() -> None:app = DesktopApp.__new__(DesktopApp)app._window = None # noqa: SLF001