Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(spaces-web): first-run permission rows follow System Settings and tick when granted (CUA-1765) (#5302)
Francesco Bonacci294364430464
diff --git a/apps/cua-spaces-web/src/bridge/__tests__/onboarding.test.tsx b/apps/cua-spaces-web/src/bridge/__tests__/onboarding.test.tsxindex f56bcfdbc0..930b822df3 100644--- a/apps/cua-spaces-web/src/bridge/__tests__/onboarding.test.tsx+++ b/apps/cua-spaces-web/src/bridge/__tests__/onboarding.test.tsx@@ -325,3 +325,31 @@ describe.skipIf(!wasmBuilt)("Done's Launch at login", () => {]);});});++describe("the permission rows of the first run", () => {+ beforeEach(() => onPlatform("MacIntel"));++ it("reads the permissions again and ticks a pane once it is granted (CUA-1765)", async () => {+ const { probe, adapter } = mount(noCore);+ const real = adapter.call.bind(adapter);+ let granted: string[] = [];+ (adapter as { call: unknown }).call = (op: string, args: unknown) =>+ op === "host.status"+ ? real(op as never, args as never).then((h: any) => ({ ...h, permissions: h.permissions.filter((p: { id: string }) => !granted.includes(p.id)) }))+ : real(op as never, args as never);+ await waitFor(() => expect(probe.flow.state).toBeTruthy());+ await waitFor(() => expect(probe.flow.permissions.map((p) => p.id)).toEqual(["screen-recording", "accessibility"]));+ expect(probe.flow.grantedPermissions).toEqual([]);++ granted = ["screen-recording"];+ await act(async () => {+ window.dispatchEvent(new Event("focus"));+ });+ await waitFor(() => expect(probe.flow.permissions.map((p) => p.id)).toEqual(["accessibility"]));+ expect(probe.flow.grantedPermissions.map((p) => p.id)).toEqual(["screen-recording"]);++ granted = ["screen-recording", "accessibility"];+ await waitFor(() => expect(probe.flow.permissions).toEqual([]), { timeout: 5000 });+ expect(probe.flow.grantedPermissions.map((p) => p.id).sort()).toEqual(["accessibility", "screen-recording"]);+ });+});diff --git a/apps/cua-spaces-web/src/bridge/hooks.ts b/apps/cua-spaces-web/src/bridge/hooks.tsindex 06253fd036..788e1e9965 100644--- a/apps/cua-spaces-web/src/bridge/hooks.ts+++ b/apps/cua-spaces-web/src/bridge/hooks.ts@@ -341,6 +341,17 @@ export function useSavedOnboarding(): SavedOnboarding {return useSyncExternalStore(subscribeSavedOnboarding, readSavedOnboarding, readSavedOnboarding);}+/** How often the permission rows are read again while one is still to grant (ms). */+export const PERMISSION_POLL_MS = 2_000;++/** The panes in `shown` that `hints` no longer lists as missing. */+export function grantedPermissionRows(shown: Record<string, string>, hints: PermissionHint[]): { id: string; title: string }[] {+ const missing = new Set(hints.filter((p) => !p.granted).map((p) => p.id));+ return Object.entries(shown)+ .filter(([id]) => !missing.has(id))+ .map(([id, title]) => ({ id, title }));+}+export interface OnboardingHook {/** The core's flow state; null until the session has loaded. */state: OnboardingFlowState | null;@@ -352,6 +363,8 @@ export interface OnboardingHook {/** macOS panes still to grant for this machine (explainers only: the* grant itself happens in System Settings). */permissions: PermissionRow[];+ /** Panes this page showed that are granted now (ticked, not dropped). */+ grantedPermissions: { id: string; title: string }[];/** This machine is already set up for access (the host choice is real). */hostConfigured: boolean;/** One image per OS for the first Space. */@@ -410,18 +423,43 @@ export function useOnboarding(): OnboardingHook {}});- // This machine's permissions, once (hosts without `host.status` show none).+ // This machine's permissions (hosts without `host.status` show none). Read+ // again every few seconds, and when the window is back in front, while any is+ // still to grant: macOS's Settings is another window, and a grant there+ // must tick here without a restart (CUA-1765).+ const pending = hints ? hints.permissions.some((p) => !p.granted) : false;+ const readHints = useRef<() => void>(() => undefined);useEffect(() => {- if (!adapter || hints) return;+ if (!adapter) return;let live = true;- adapter- .call("host.status", {})- .then((h) => live && setHints({ permissions: h.permissions ?? [], configured: h.configured }))- .catch(() => live && setHints({ permissions: [], configured: false }));+ readHints.current = () => {+ adapter+ .call("host.status", {})+ .then((h) => live && setHints({ permissions: h.permissions ?? [], configured: h.configured }))+ .catch(() => live && setHints((cur) => cur ?? { permissions: [], configured: false }));+ };+ readHints.current();return () => {live = false;};- }, [adapter, hints]);+ }, [adapter]);+ useEffect(() => {+ if (!pending) return;+ const again = () => readHints.current();+ const timer = setInterval(again, PERMISSION_POLL_MS);+ window.addEventListener("focus", again);+ return () => {+ clearInterval(timer);+ window.removeEventListener("focus", again);+ };+ }, [pending]);+ // The panes this page has shown, so one that is granted now shows ticked instead of vanishing.+ const [shown, setShown] = useState<Record<string, string>>({});+ useEffect(() => {+ if (!hints) return;+ const missing = hints.permissions.filter((p) => !p.granted);+ if (missing.some((p) => !(p.id in shown))) setShown((cur) => ({ ...cur, ...Object.fromEntries(missing.map((p) => [p.id, p.label])) }));+ }, [hints, shown]);const drawn = state ? onboardingView(core, state) : null;// No switch until the host has said what the setting is: an "on" it@@ -464,6 +502,7 @@ export function useOnboarding(): OnboardingHook {copy: onboardingCopy(core),signInText,permissions: hints ? permissionRows(core, hints.permissions) : [],+ grantedPermissions: hints ? grantedPermissionRows(shown, hints.permissions) : [],hostConfigured: hints?.configured ?? false,images: firstSpaceImages(core),launchAtLogin: mode === "electron" ? (view?.launchAtLogin ?? null) : null,diff --git a/apps/cua-spaces-web/src/routes/onboarding/index.tsx b/apps/cua-spaces-web/src/routes/onboarding/index.tsxindex 4287720c6a..5f3ad3fbce 100644--- a/apps/cua-spaces-web/src/routes/onboarding/index.tsx+++ b/apps/cua-spaces-web/src/routes/onboarding/index.tsx@@ -195,7 +195,7 @@ function Columns({ flow, view, agents }: { flow: OnboardingHook; view: Onboardin</div></div>{/* Only hosts need Screen Recording and Accessibility (the core's host setup). */}- {settingUpHost && flow.permissions.length > 0 ? <Permissions flow={flow} /> : null}+ {settingUpHost && (flow.permissions.length > 0 || flow.grantedPermissions.length > 0) ? <Permissions flow={flow} /> : null}{view.step === "done" ? <FirstSpace images={flow.images} /> : null}</div>);@@ -294,6 +294,14 @@ function Permissions({ flow }: { flow: OnboardingHook }) {</h2><p className="mb-3 text-xs text-muted-foreground">macOS asks for each one itself. Cua Spaces can't turn them on for you.</p><Card className="divide-y p-0">+ {flow.grantedPermissions.map((p) => (+ <div key={p.id} className="flex items-center justify-between gap-6 px-4 py-3" data-granted="true">+ <div className="text-[13px]">{p.title}</div>+ <span className="text-xs text-muted-foreground" aria-label={`${p.title} granted`}>+ ✓ Granted+ </span>+ </div>+ ))}{flow.permissions.map((p) => {const url = p.settingsUrl?.startsWith("x-apple.systempreferences:") ? p.settingsUrl : null;return (