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
perf(society): suspend covered canvases while agent cards are open
rubenluetke10-beepb76145912dea
diff --git a/jarvis/ui/web/frontend/src/hooks/useCanvasAwake.test.tsx b/jarvis/ui/web/frontend/src/hooks/useCanvasAwake.test.tsxnew file mode 100644index 0000000000..334680c318--- /dev/null+++ b/jarvis/ui/web/frontend/src/hooks/useCanvasAwake.test.tsx@@ -0,0 +1,48 @@+import { useRef } from "react";+import { act, cleanup, render, screen } from "@testing-library/react";+import { afterEach, expect, test, vi } from "vitest";+import { CanvasActivity, useCanvasAwake } from "./useCanvasAwake";++afterEach(() => { cleanup(); vi.unstubAllGlobals(); });++function Surface() {+ const ref = useRef<HTMLDivElement>(null);+ const awake = useCanvasAwake(ref);+ return <div ref={ref} data-testid="surface" data-awake={awake} />;+}++test("covered canvases sleep immediately and resume only when also in the viewport", () => {+ const observers: FakeObserver[] = [];+ class FakeObserver {+ disconnected = false;+ constructor(readonly callback: IntersectionObserverCallback) { observers.push(this); }+ observe() {}+ disconnect() { this.disconnected = true; }+ emit(isIntersecting: boolean) {+ this.callback([{ isIntersecting } as IntersectionObserverEntry], this as unknown as IntersectionObserver);+ }+ }+ vi.stubGlobal("IntersectionObserver", FakeObserver);+ const tree = (active: boolean) => <CanvasActivity.Provider value={active}><Surface /></CanvasActivity.Provider>;+ const view = render(tree(true));+ expect(screen.getByTestId("surface").dataset.awake).toBe("true");+ view.rerender(tree(false));+ expect(screen.getByTestId("surface").dataset.awake).toBe("false");+ act(() => observers[0].emit(false));+ view.rerender(tree(true));+ expect(screen.getByTestId("surface").dataset.awake).toBe("false");+ act(() => observers[0].emit(true));+ expect(screen.getByTestId("surface").dataset.awake).toBe("true");+ expect(observers).toHaveLength(1);+ expect(observers[0].disconnected).toBe(false);+ view.unmount();+ expect(observers[0].disconnected).toBe(true);+});++test("explicit occlusion also works in shells without IntersectionObserver", () => {+ vi.stubGlobal("IntersectionObserver", undefined);+ const view = render(<CanvasActivity.Provider value={false}><Surface /></CanvasActivity.Provider>);+ expect(screen.getByTestId("surface").dataset.awake).toBe("false");+ view.rerender(<CanvasActivity.Provider value={true}><Surface /></CanvasActivity.Provider>);+ expect(screen.getByTestId("surface").dataset.awake).toBe("true");+});diff --git a/jarvis/ui/web/frontend/src/hooks/useCanvasAwake.ts b/jarvis/ui/web/frontend/src/hooks/useCanvasAwake.tsindex 687f88b32b..ee3fe27628 100644--- a/jarvis/ui/web/frontend/src/hooks/useCanvasAwake.ts+++ b/jarvis/ui/web/frontend/src/hooks/useCanvasAwake.ts@@ -10,9 +10,13 @@** The society README mandates this pattern for every world/card canvas.*/-import { useEffect, useState, type RefObject } from "react";+import { createContext, useContext, useEffect, useState, type RefObject } from "react";++/** Explicit occlusion, independent of unreliable WebView document visibility. */+export const CanvasActivity = createContext(true);export function useCanvasAwake(hostRef: RefObject<HTMLElement | null>): boolean {+ const active = useContext(CanvasActivity);const [awake, setAwake] = useState(true);useEffect(() => {@@ -29,7 +33,7 @@ export function useCanvasAwake(hostRef: RefObject<HTMLElement | null>): booleanreturn () => observer.disconnect();}, [hostRef]);- return awake;+ return active && awake;}export default useCanvasAwake;diff --git a/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx b/jarvis/ui/web/frontend/src/views/society/SocietyView.tsxindex d3db40a367..7f262cd7c1 100644--- a/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx+++ b/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx@@ -21,6 +21,7 @@ import type { PlaceId } from "@/components/society/world/islandLayout";import { useSocietyRoster } from "@/components/society/data";import { RosterRail } from "@/components/society/roster/RosterRail";import { useModelMenuData } from "@/components/society/chat/useModelMenuData";+import { CanvasActivity } from "@/hooks/useCanvasAwake";const JarvisAgentsBoard = lazy(() =>import("@/views/JarvisAgentsView").then((m) => ({ default: m.JarvisAgentsView })),@@ -74,9 +75,11 @@ export function SocietyView() {<span className="ml-auto">{t("society.strip.world_pending")}</span></div><div className="relative min-h-0 flex-1">- <Suspense fallback={null}>- <JarvisAgentsBoard onSelectAgent={onIslandSelect} onSelectPlace={onIslandPlace} />- </Suspense>+ <CanvasActivity.Provider value={!openAgent && !openPlace && !creating}>+ <Suspense fallback={null}>+ <JarvisAgentsBoard onSelectAgent={onIslandSelect} onSelectPlace={onIslandPlace} />+ </Suspense>+ </CanvasActivity.Provider></div></div><RosterRail