Skip to content

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.

fix(wiki): the awake gate asks, instead of waiting to be told

Harald98b803edb16c
diff --git a/jarvis/ui/web/frontend/src/hooks/useGraphAwake.test.ts b/jarvis/ui/web/frontend/src/hooks/useGraphAwake.test.ts
index a90f9adcad..cbba0b0a80 100644
--- a/jarvis/ui/web/frontend/src/hooks/useGraphAwake.test.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useGraphAwake.test.ts
@@ -127,6 +127,88 @@ describe("useGraphAwake", () => {
expect(graph.pauseAnimation).not.toHaveBeenCalled();
});
+ it("pauses without any event at all", () => {
+ // The case the first cut missed entirely: a window the user never clicked
+ // into never fires `blur` when they work elsewhere. Measured in the real
+ // WebView, `hasFocus()` was already false while the page painted 60 fps,
+ // because nothing had asked. The timer is what asks.
+ vi.useFakeTimers();
+ try {
+ const graph = engine();
+ pretend({ focused: true });
+ renderHook(() => useGraphAwake({ current: graph }));
+
+ pretend({ focused: false });
+ expect(graph.pauseAnimation).not.toHaveBeenCalled();
+
+ act(() => {
+ vi.advanceTimersByTime(2_500);
+ });
+
+ expect(graph.pauseAnimation).toHaveBeenCalledTimes(1);
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
+ it("resumes without any event at all", () => {
+ vi.useFakeTimers();
+ try {
+ const graph = engine();
+ pretend({ focused: false });
+ renderHook(() => useGraphAwake({ current: graph }));
+ act(() => {
+ vi.advanceTimersByTime(2_500);
+ });
+ expect(graph.pauseAnimation).toHaveBeenCalledTimes(1);
+
+ pretend({ focused: true });
+ act(() => {
+ vi.advanceTimersByTime(2_500);
+ });
+
+ expect(graph.resumeAnimation).toHaveBeenCalledTimes(1);
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
+ it("polls at most once per state change, not once per tick", () => {
+ vi.useFakeTimers();
+ try {
+ const graph = engine();
+ pretend({ focused: false });
+ renderHook(() => useGraphAwake({ current: graph }));
+
+ act(() => {
+ vi.advanceTimersByTime(30_000);
+ });
+
+ expect(graph.pauseAnimation).toHaveBeenCalledTimes(1);
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
+ it("stops polling once unmounted", () => {
+ vi.useFakeTimers();
+ try {
+ const graph = engine();
+ pretend({ focused: true });
+ const view = renderHook(() => useGraphAwake({ current: graph }));
+ view.unmount();
+
+ pretend({ focused: false });
+ act(() => {
+ vi.advanceTimersByTime(30_000);
+ });
+
+ expect(graph.pauseAnimation).not.toHaveBeenCalled();
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it("survives a ref that has no instance yet", () => {
const ref: { current: GraphEngineApi | undefined } = { current: undefined };
pretend({ focused: true });
diff --git a/jarvis/ui/web/frontend/src/hooks/useGraphAwake.ts b/jarvis/ui/web/frontend/src/hooks/useGraphAwake.ts
index 4f09d79d44..c1ab4e3b2f 100644
--- a/jarvis/ui/web/frontend/src/hooks/useGraphAwake.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useGraphAwake.ts
@@ -37,6 +37,21 @@ export interface GraphEngineApi {
*/
const MAX_ATTACH_FRAMES = 120;
+/**
+ * Why this polls instead of trusting the events.
+ *
+ * The first cut listened for `blur`/`focus`/`visibilitychange` alone and did
+ * nothing at all in the case it was written for. A window the user has never
+ * clicked into never HAD focus, so it never fires `blur` when they work
+ * elsewhere — the gate simply never woke up to look. Measured in the real
+ * WebView 2026-08-21: `document.hasFocus()` was already false and the page
+ * was still painting a full 60 fps, because nothing had asked.
+ *
+ * Two seconds is well under the time it takes to notice a still map, and one
+ * `hasFocus()` read on a timer is nothing next to the frames it saves.
+ */
+const CHECK_MS = 2_000;
+
/** Is anyone actually looking at this document right now? */
function isWatched(): boolean {
if (typeof document === "undefined") return true;
@@ -77,12 +92,16 @@ export function useGraphAwake(
};
apply();
+ // The events are the fast path — they react the instant you click away.
+ // The timer is the one that actually catches the common case; see above.
+ const timer = window.setInterval(apply, CHECK_MS);
document.addEventListener("visibilitychange", apply);
window.addEventListener("focus", apply);
window.addEventListener("blur", apply);
return () => {
cancelAnimationFrame(frame);
+ window.clearInterval(timer);
document.removeEventListener("visibilitychange", apply);
window.removeEventListener("focus", apply);
window.removeEventListener("blur", apply);