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(appshot): show the editor tools when the pencil opens it
rubenluetke10-beep3433b2b1be32
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex 403dc14e45..3c7592c50a 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -895,6 +895,45 @@ def _primary_screen_size(webview_module: Any) -> tuple[int, int] | None:return None+def _repaint_webview_shown_from_hidden(window: Any) -> None:+ """Paint a WebView that was created hidden.++ On Windows the editor window is created hidden so the first click is+ instant. WebView2 builds its surface while that form is hidden, then+ ``show()`` reveals a blank frame — the window's own background, with none+ of the page — until the form's size actually changes. One pixel out and+ back is enough. Other platforms paint on show, so this is a no-op there.+ """+ if sys.platform != "win32":+ return+ size = _window_size_for_repaint(window)+ if size is None:+ return+ width, height = size+ try:+ window.resize(width, height + 1)+ window.resize(width, height)+ except Exception: # noqa: BLE001 - the window is already shown; a failed nudge must not fail the open+ from loguru import logger++ logger.debug("The appshot editor window could not be nudged to paint", exc_info=True)+++def _window_size_for_repaint(window: Any) -> tuple[int, int] | None:+ """The window's current size, or the size it was created at."""+ for read in (+ lambda: (int(window.width), int(window.height)),+ lambda: (int(window.initial_width), int(window.initial_height)),+ ):+ try:+ width, height = read()+ except Exception: # noqa: BLE001 - a cross-thread size read can fail; try the other source+ continue+ if width >= 2 and height >= 2:+ return width, height+ return None++def _bring_window_to_front_by_title(title: str) -> bool:"""Win32 fallback for hidden/minimized pywebview windows.@@ -5299,16 +5338,25 @@ class DesktopApp:return self.open_detached_window("jarvisx-editor", query=f"item={item_id}")def _show_warm_editor(self, window: Any, query: str, fallback: str) -> dict[str, Any]:- """Show the kept-warm appshot editor on the appshot named in ``query``."""+ """Show the kept-warm appshot editor on the appshot (or recording) in ``query``."""shot_id = query.partition("appshot=")[2].split("&", 1)[0]+ hook = "__jarvisOpenAppshot"+ if not shot_id:+ # The same window plays and trims screen recordings.+ shot_id = query.partition("recording=")[2].split("&", 1)[0]+ hook = "__jarvisOpenRecording"pointed = Falseif shot_id:try:- pointed = bool(+ # Only a real boolean true means the page switched in place.+ # Anything else (still loading, a script error object, a+ # string) must navigate, or the window opens on the empty shell.+ pointed = (window.evaluate_js(- "typeof window.__jarvisOpenAppshot === 'function'"- f" && window.__jarvisOpenAppshot({json.dumps(shot_id)})"+ f"typeof window.{hook} === 'function'"+ f" && window.{hook}({json.dumps(shot_id)})")+ is True)except Exception: # noqa: BLE001 - still loading: navigate insteadpointed = False@@ -5322,6 +5370,8 @@ class DesktopApp:logger.opt(exception=exc).warning("The appshot editor window could not be shown")return {"ok": False, "reason": f"{type(exc).__name__}: {exc}"}+ # After show: a window created hidden stays a blank frame until resized.+ _repaint_webview_shown_from_hidden(window)_bring_window_to_front_by_title(self._detached_title("appshot-editor"))return {"ok": True, "already_open": True, "view": "appshot-editor"}diff --git a/jarvis/ui/web/frontend/index.html b/jarvis/ui/web/frontend/index.htmlindex 319d2b8261..4117d17af6 100644--- a/jarvis/ui/web/frontend/index.html+++ b/jarvis/ui/web/frontend/index.html@@ -103,6 +103,15 @@--jbs-sub: #7a7a7a;}html, body { margin: 0; height: 100%; background: var(--jbs-bg); }+ /* The editor window is created hidden. Laid out that way, `100vh` can+ stay 0 after the window is shown, and a shell sized with it collapses+ to nothing — the window is only this ground colour, with no toolbar.+ The editor fills the viewport with `fixed inset-0`. `#root` is a real+ box too, so anything still sized in percent has a height to fill. */+ html.jarvis-quiet-boot, html.jarvis-quiet-boot body, html.jarvis-quiet-boot #root {+ height: 100%;+ min-height: 100%;+ }.jarvis-quiet-boot #jarvis-boot-splash { display: none !important; }#jarvis-boot-splash {position: fixed; inset: 0; z-index: 2147483000;diff --git a/jarvis/ui/web/frontend/src/main.tsx b/jarvis/ui/web/frontend/src/main.tsxindex 977505ba48..7bff4667a5 100644--- a/jarvis/ui/web/frontend/src/main.tsx+++ b/jarvis/ui/web/frontend/src/main.tsx@@ -150,7 +150,11 @@ function renderApp(): void {><AuthGate quiet={isEditorWindow}>{isEditorWindow ? (- <React.Suspense fallback={null}>+ <React.Suspense+ fallback={+ <div className="fixed inset-0 bg-popover" data-testid="appshot-editor-window" />+ }+ ><AppshotEditorWindow /></React.Suspense>) : (diff --git a/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.test.tsx b/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.test.tsxindex 6a59ad5e86..ffa2080c5d 100644--- a/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.test.tsx+++ b/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.test.tsx@@ -61,6 +61,8 @@ describe("the appshot editor window", () => {};render(<AppshotEditorWindow deps={deps} />);await screen.findByTestId("appshot-editor-canvas");+ expect(screen.getByTestId("appshot-editor-window").className).toContain("fixed");+ expect(screen.getByTestId("appshot-editor-window").className).toContain("inset-0");expect(screen.getByTestId("appshot-editor").getAttribute("data-variant")).toBe("window");fireEvent.click(screen.getByTestId("appshot-editor-close"));@@ -125,6 +127,7 @@ describe("the appshot editor window", () => {act(() => {expect(window.__jarvisOpenAppshot!("a1b2c3d4")).toBe(true);});+ expect(window.location.search).toContain("appshot=a1b2c3d4");await screen.findByTestId("appshot-editor-canvas");fireEvent.click(screen.getByTestId("appshot-editor-close"));diff --git a/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.tsx b/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.tsxindex c7f8c552f0..4e3b85a1c4 100644--- a/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.tsx+++ b/jarvis/ui/web/frontend/src/views/AppshotEditorWindow.tsx@@ -3,10 +3,13 @@ import { useCallback, useEffect, useRef, useState } from "react";import { ToastLayer } from "@/components/ToastLayer";import { loadLocaleChunk } from "@/i18n";import { AppshotEditor, type EditorExit } from "@/views/AppshotEditor";+import { AppshotVideoEditor } from "@/views/AppshotVideoEditor";/*** The appshot editor as its own desktop window (`?view=appshot-editor&solo=1- * &appshot=<id>`), opened by a click on the corner card.+ * &appshot=<id>`), opened by a click on the corner card. Pointed at a screen+ * recording (`&recording=<id>`, or `window.__jarvisOpenRecording`) the same+ * window is the video editor instead.* Nothing of the app is loaded around it.** When it closes the appshot goes back into the screen corner@@ -26,11 +29,34 @@ export function appshotIdFromUrl(search: string): string {return /^[0-9a-f]{8,64}$/.test(id) ? id : "";}+/** The screen recording this window plays and trims, from its URL; empty when none. */+export function recordingIdFromUrl(search: string): string {+ const id = new URLSearchParams(search).get("recording") ?? "";+ return /^[0-9a-f]{32}$/.test(id) ? id : "";+}+/** Is this document the editor window rather than the app? */export function isAppshotEditorWindow(search: string): boolean {return new URLSearchParams(search).get("view") === APPSHOT_EDITOR_VIEW;}+/**+ * Remember which picture this window is on.+ *+ * The warm window is opened without an id and pointed later in memory. A+ * reload of that address (the blank-window watchdog, a rebuilt bundle) would+ * otherwise come back as the empty gray shell. The address is the backup.+ */+function rememberEditorTarget(kind: "appshot" | "recording", id: string): void {+ const url = new URL(window.location.href);+ url.searchParams.delete("appshot");+ url.searchParams.delete("recording");+ if (id) url.searchParams.set(kind, id);+ const next = `${url.pathname}${url.search}${url.hash}`;+ const current = `${window.location.pathname}${window.location.search}${window.location.hash}`;+ if (next !== current) window.history.replaceState(null, "", next);+}+export interface EditorWindowDeps {returnCard: (id: string, flyFrom?: EditorExit["flyFrom"]) => Promise<unknown>;closeWindow: () => Promise<unknown>;@@ -55,6 +81,8 @@ declare global {interface Window {/** The desktop shell points the warm (hidden) editor window at an appshot. */__jarvisOpenAppshot?: (id: string) => boolean;+ /** The same window, pointed at a screen recording: it plays and trims it. */+ __jarvisOpenRecording?: (id: string) => boolean;}}@@ -63,6 +91,9 @@ export function AppshotEditorWindow({ deps = browserDeps }: { deps?: EditorWindo// appshot and be pointed at one later (window.__jarvisOpenAppshot), so the// editor opens at once instead of booting a fresh window each time.const [appshotId, setAppshotId] = useState(() => appshotIdFromUrl(window.location.search));+ const [recordingId, setRecordingId] = useState(() =>+ appshotIdFromUrl(window.location.search) ? "" : recordingIdFromUrl(window.location.search),+ );const [session, setSession] = useState(0);const closing = useRef(false);@@ -73,12 +104,25 @@ export function AppshotEditorWindow({ deps = browserDeps }: { deps?: EditorWindoconst valid = appshotIdFromUrl(`?appshot=${encodeURIComponent(id)}`);if (!valid) return false;closing.current = false;+ rememberEditorTarget("appshot", valid);+ setRecordingId("");setAppshotId(valid);setSession((n) => n + 1);return true;};+ window.__jarvisOpenRecording = (id: string) => {+ const valid = recordingIdFromUrl(`?recording=${encodeURIComponent(id)}`);+ if (!valid) return false;+ closing.current = false;+ rememberEditorTarget("recording", valid);+ setAppshotId("");+ setRecordingId(valid);+ setSession((n) => n + 1);+ return true;+ };return () => {delete window.__jarvisOpenAppshot;+ delete window.__jarvisOpenRecording;};}, []);@@ -93,15 +137,29 @@ export function AppshotEditorWindow({ deps = browserDeps }: { deps?: EditorWindo.catch(() => undefined).finally(() => {setAppshotId("");+ rememberEditorTarget("appshot", "");void deps.closeWindow().catch(() => undefined);});}, [appshotId, deps]);+ // A video has no corner card to return to: closing just hides the window+ // and forgets the video, so a hidden window never keeps playing or flashes it.+ const closeVideo = useCallback(() => {+ if (closing.current) return;+ closing.current = true;+ setRecordingId("");+ rememberEditorTarget("recording", "");+ void deps.closeWindow().catch(() => undefined);+ }, [deps]);+return (- <div className="h-screen w-screen overflow-hidden bg-popover" data-testid="appshot-editor-window">+ <div className="fixed inset-0 overflow-hidden bg-popover" data-testid="appshot-editor-window">{appshotId && (<AppshotEditor key={session} appshotId={appshotId} onClose={close} variant="window" />)}+ {!appshotId && recordingId && (+ <AppshotVideoEditor key={session} recordingId={recordingId} onClose={closeVideo} />+ )}<ToastLayer /></div>);diff --git a/tests/unit/ui/test_appshot_editor_warm.py b/tests/unit/ui/test_appshot_editor_warm.pyindex a56c037dd2..15e26721dd 100644--- a/tests/unit/ui/test_appshot_editor_warm.py+++ b/tests/unit/ui/test_appshot_editor_warm.py@@ -26,8 +26,10 @@ class _Hook:class _Window:- def __init__(self, *, page_ready: bool = True) -> None:+ def __init__(self, *, page_ready: bool = True, width: int = 900, height: int = 600) -> None:self.page_ready = page_ready+ self.width = width+ self.height = heightself.events = _Events()self.calls: list[str] = []@@ -41,6 +43,11 @@ class _Window:def show(self) -> None:self.calls.append("show")+ def resize(self, width: int, height: int) -> None:+ self.calls.append(f"resize {width}x{height}")+ self.width = width+ self.height = height+def hide(self) -> None:self.calls.append("hide")@@ -88,11 +95,51 @@ def test_a_page_still_loading_is_navigated_then_shown(monkeypatch: pytest.Monkeyresult = app.open_detached_window("appshot-editor", query="appshot=a1b2c3d4")assert result["ok"] is True- assert window.calls == [+ assert window.calls[:3] == ["js","load http://127.0.0.1:47821/?view=appshot-editor&solo=1&appshot=a1b2c3d4","show",]+ # Windows paints a WebView that was created hidden only after a size change.+ if sys.platform == "win32":+ assert window.calls[3:] == ["resize 900x601", "resize 900x600"]+ else:+ assert window.calls[3:] == []+++def test_a_script_result_that_is_not_true_still_loads_the_shot(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A truthy non-boolean (an error object, a leftover string) is not success.++ Treating it as success skipped navigation and showed the empty gray shell.+ """+ app = _app(monkeypatch)+ window = _Window()+ window.evaluate_js = lambda _js: window.calls.append("js") or {"pywebview": "still booting"} # type: ignore[method-assign]+ app._detached_windows["appshot-editor"] = window # noqa: SLF001++ result = app.open_detached_window("appshot-editor", query="appshot=a1b2c3d4")++ assert result["ok"] is True+ assert any(call.startswith("load ") and "appshot=a1b2c3d4" in call for call in window.calls)+ assert "show" in window.calls+++def test_showing_the_warm_editor_on_windows_nudges_its_size(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.setattr("jarvis.ui.desktop_app.sys.platform", "win32")+ app = _app(monkeypatch)+ window = _Window(width=1024, height=662)+ app._detached_windows["appshot-editor"] = window # noqa: SLF001++ result = app.open_detached_window("appshot-editor", query="appshot=a1b2c3d4")++ assert result["ok"] is True+ assert window.calls[-2:] == ["resize 1024x663", "resize 1024x662"]+ assert window.width == 1024+ assert window.height == 662def test_closing_the_editor_hides_it_and_keeps_it(monkeypatch: pytest.MonkeyPatch) -> None: