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): follow window drags when the notch setting turns on live (CUA-1618) (#5189)
ddupont29598e25ba60
diff --git a/apps/cua-spaces-desktop/src/main.ts b/apps/cua-spaces-desktop/src/main.tsindex 1e14707f13..6115eb7b48 100644--- a/apps/cua-spaces-desktop/src/main.ts+++ b/apps/cua-spaces-desktop/src/main.ts@@ -22,7 +22,7 @@ import { recordLaunch, refreshAfterUpdate } from "./model/update-refresh";import { loadNative } from "./native/load";import { nativeDir } from "./native/location";import { connectNotch, type NotchCore } from "./notch";-import { dropOnSpace, feedNotch, notchTeleport, notchThumbnail, openSpaceFromNotch, teleportFromNotch, type NotchFeedUi } from "./notch-feed";+import { dropOnSpace, feedNotch, followDragReadiness, notchTeleport, notchThumbnail, openSpaceFromNotch, teleportFromNotch, type NotchFeedUi } from "./notch-feed";import { createPipWindows } from "./pip";import { electronKeyvaultPrompts } from "./prompts";import { APP_ORIGIN, handleAppProtocol, registerSchemePrivileges } from "./protocol";@@ -230,8 +230,8 @@ async function startNativeHost(showRoute: (route: string) => void, globalShortcu});if (notch) {feedNotch(notch, model);- // Window drags need the SDK: look again once it is in.- if (!model.startup.isReady) model.startup.onReady.push(() => notch.recheckPermission());+ // Window drags need the SDK: look now and whenever the launch is (again) ready, whichever of the two came first.+ followDragReadiness(notch, model.startup);}return { env, bridge, background };}diff --git a/apps/cua-spaces-desktop/src/notch-feed.ts b/apps/cua-spaces-desktop/src/notch-feed.tsindex db102f7831..2b61d6a71d 100644--- a/apps/cua-spaces-desktop/src/notch-feed.ts+++ b/apps/cua-spaces-desktop/src/notch-feed.ts@@ -132,3 +132,26 @@ export function feedNotch(notch: Pick<Notch, "setSpaces" | "setShown" | "setActi];return () => stops.forEach((s) => s());}++/** What `followDragReadiness` reads of the launch (`StartupModel`). */+export interface DragReadiness {+ readonly isReady: boolean;+ /** Called on every change; returns the unsubscribe. */+ subscribe(listener: () => void): () => void;+}++/**+ * Window-drag tracking needs the SDK (the launch's end) and the notch (its+ * helper connecting). Either may come first, so this checks now, once the+ * notch is connected, and again on every launch change while it is ready;+ * the helper's own (re)connects check again too (`startNotch`). The check+ * is idempotent: a running monitor stays as it is. Returns the stop.+ */+export function followDragReadiness(notch: Pick<Notch, "recheckPermission">, startup: DragReadiness): () => void {+ const check = () => {+ if (startup.isReady) notch.recheckPermission();+ };+ const stop = startup.subscribe(check);+ check();+ return stop;+}diff --git a/apps/cua-spaces-desktop/src/notch.ts b/apps/cua-spaces-desktop/src/notch.tsindex 68e2050bfe..246c64feae 100644--- a/apps/cua-spaces-desktop/src/notch.ts+++ b/apps/cua-spaces-desktop/src/notch.ts@@ -158,9 +158,12 @@ export function startNotch(host: NotchHost, options: StartNotchOptions): Notch {send({ type: "hello", v: NOTCH_PROTOCOL_VERSION, ...model.motion() });model.resend();for (const [id, image] of thumbnails) send({ type: "thumbnail", id, image });+ // Connected (or reconnected): follow window drags if they are not followed yet.+ model.recheckPermission();},});helper.start();+ // Also when the helper did not start (it restarts later).model.recheckPermission();return {diff --git a/apps/cua-spaces-desktop/test/notch.test.ts b/apps/cua-spaces-desktop/test/notch.test.tsindex ad1b7e68bd..99d8ad8e9c 100644--- a/apps/cua-spaces-desktop/test/notch.test.ts+++ b/apps/cua-spaces-desktop/test/notch.test.ts@@ -8,7 +8,7 @@ import * as path from "node:path";import { PassThrough } from "node:stream";import { describe, expect, it, vi } from "vitest";import { helperPath, notchSupported, startNotch, type NotchActions, type WindowDragEvent, type WindowTargets } from "../src/notch";-import { notchTeleport } from "../src/notch-feed";+import { followDragReadiness, notchTeleport } from "../src/notch-feed";import { fakeCore, manualClock, MOTION } from "./fakeNotchCore";const require = createRequire(import.meta.url);@@ -285,3 +285,132 @@ describe("window drags onto the notch", () => {expect((t.captureWindowThumbnail(7, 320) as ArrayBuffer).byteLength).toBe(3);});});++// CUA-1618: window-drag tracking needs both the SDK (the launch's end) and+// the notch (its helper connecting), in either order, and follows the+// "Spaces tab in the notch" setting live.+describe("window-drag tracking, whichever comes first", () => {+ function lifecycle(o: { helperUp: boolean }) {+ const clock = manualClock();+ const children: FakeChild[] = [];+ let helperUp = o.helperUp;+ const monitors: { stop: ReturnType<typeof vi.fn> }[] = [];+ // The SDK's teleport handle: none until the launch hands it over.+ let sdk: unknown = null;+ const sdkIn = () => {+ sdk = {+ windowDragSupported: () => true,+ windowDragPermitted: () => true,+ requestWindowDragPermission: () => true,+ startWindowDrag: () => {+ const m = { stop: vi.fn() };+ monitors.push(m);+ return m;+ },+ captureWindowThumbnail: () => null,+ };+ };+ const listeners = new Set<() => void>();+ const startup = {+ isReady: false,+ subscribe(l: () => void) {+ listeners.add(l);+ return () => void listeners.delete(l);+ },+ ready() {+ this.isReady = true;+ for (const l of [...listeners]) l();+ },+ };+ const notch = startNotch(+ {+ core: fakeCore().core,+ actions: { openSpace() {}, openMain() {}, openSettings() {}, openAccess() {}, dismissAccess() {}, teleport() {}, drop() {} },+ teleport: notchTeleport(() => sdk as never),+ },+ {+ path: "/helper",+ clock,+ log: () => {},+ process: {+ // The helper still connecting: its first start fails and it restarts after the backoff.+ spawn: () => {+ if (!helperUp) {+ helperUp = true;+ throw new Error("not yet");+ }+ const c = new FakeChild();+ children.push(c);+ return c as unknown as ChildProcess;+ },+ after: clock.after,+ now: clock.now,+ },+ },+ );+ /** Lets the monitor's deferred start (`notchTeleport`) run. */+ const settle = () => new Promise((r) => setTimeout(r, 5));+ return { notch, clock, children, monitors, sdkIn, startup, settle };+ }++ it("starts when the launch finished before the notch was wired to it (the startup race)", async () => {+ const { notch, monitors, sdkIn, startup, settle, clock, children } = lifecycle({ helperUp: false });+ await settle();+ expect(monitors).toHaveLength(0);+ // The launch ends while the notch is still connecting: no change is seen after the wiring.+ sdkIn();+ startup.isReady = true;+ followDragReadiness(notch, startup);+ await settle();+ expect(monitors).toHaveLength(1);+ // The helper connects later: still one monitor.+ clock.advance(500);+ expect(children).toHaveLength(1);+ await settle();+ expect(monitors).toHaveLength(1);+ notch.stop();+ });++ it("starts once a delayed helper connects, the SDK having come in meanwhile", async () => {+ const { notch, monitors, sdkIn, settle, clock, children } = lifecycle({ helperUp: false });+ await settle();+ expect(children).toHaveLength(0);+ sdkIn();+ await settle();+ expect(monitors).toHaveLength(0);+ clock.advance(500);+ expect(children).toHaveLength(1);+ await vi.waitFor(() => expect(monitors).toHaveLength(1));+ notch.stop();+ });++ it("starts once the launch finishes after the notch connected", async () => {+ const { notch, monitors, sdkIn, startup, settle } = lifecycle({ helperUp: true });+ followDragReadiness(notch, startup);+ await settle();+ expect(monitors).toHaveLength(0);+ sdkIn();+ startup.ready();+ await vi.waitFor(() => expect(monitors).toHaveLength(1));+ notch.stop();+ });++ it("stops when the setting hides the notch and starts again when it shows it, without a relaunch", async () => {+ const { notch, monitors, sdkIn, startup, settle } = lifecycle({ helperUp: true });+ notch.setShown(false);+ sdkIn();+ startup.ready();+ followDragReadiness(notch, startup);+ await settle();+ expect(monitors).toHaveLength(0);+ // Turned on while the app runs.+ notch.setShown(true);+ await vi.waitFor(() => expect(monitors).toHaveLength(1));+ notch.setShown(false);+ expect(monitors[0]!.stop).toHaveBeenCalledTimes(1);+ notch.setShown(true);+ await vi.waitFor(() => expect(monitors).toHaveLength(2));+ expect(monitors[1]!.stop).not.toHaveBeenCalled();+ notch.stop();+ });+});diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Notch/NotchController.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Notch/NotchController.swiftindex 6498ceda02..e597c1e074 100644--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Notch/NotchController.swift+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Notch/NotchController.swift@@ -107,23 +107,30 @@ public final class NotchController {if shown { show() } else { hide() }}- /// Shows the panel on the notched display (else the main one).+ /// Shows the panel on the notched display (else the main one), and+ /// follows window drags again: at launch and whenever the setting turns+ /// on while the app runs (CUA-1618), panel new or not.public func show() {- if isShown, panel != nil { return }- if !isShown {+ let wasShown = isShown+ if !wasShown {isShown = truemodel.send(.visibility(shown: true))}- if let panel {- place()- panel.orderFrontRegardless()- recheckPermission()- return- }- guard makesPanel else {- recheckPermission()- return+ if makesPanel {+ if let panel {+ if !wasShown {+ place()+ panel.orderFrontRegardless()+ }+ } else {+ makePanel()+ }}+ recheckPermission()+ }++ /// The panel, made once and put on screen.+ private func makePanel() {let panel = NotchPanel()let view = NotchHostingView(rootView: NotchContentView(surface: self))view.sizingOptions = []diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/NotchTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/NotchTests.swiftindex bef698069f..00b209f645 100644--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/NotchTests.swift+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/NotchTests.swift@@ -514,6 +514,39 @@ struct NotchTests {#expect(c.isShown && !m.notch.view.hidden)c.setShown(false)}++ /// CUA-1618: the setting off at launch, the SDK in, then the setting+ /// turned on while the app runs: window drags are followed (onto the+ /// notch and the New UI's tiles) without a relaunch, stop when it turns+ /// off and start again when it turns back on.+ @Test func turningTheNotchOnLiveStartsWindowDragsAndOffStopsThem() async {+ let m = ViewModelTests().makeModel(FixtureSpacesBackend())+ let c = NotchController(model: m.notch)+ c.makesPanel = false+ m.settings.menuBar = true+ AppDelegate.followNotchSetting(m, c)+ #expect(!c.isShown)+ // The SDK comes in after the launch (`followWindowDrags`).+ var started = 0+ c.permitted = { true }+ c.startDrags = { started += 1 }+ c.recheckPermission()+ #expect(started == 0 && !c.dragsRunning, "no drag monitor while hidden")+ await m.choose(row: "notch", option: "show")+ for _ in 0..<20 where !c.isShown { try? await Task.sleep(for: .milliseconds(20)) }+ #expect(c.isShown)+ #expect(started == 1 && c.dragsRunning, "turned on live: window drags are followed")+ await m.choose(row: "notch", option: "hide")+ for _ in 0..<20 where c.isShown { try? await Task.sleep(for: .milliseconds(20)) }+ #expect(!c.isShown && !c.dragsRunning, "turned off: the monitor stops")+ await m.choose(row: "notch", option: "show")+ for _ in 0..<20 where !c.isShown { try? await Task.sleep(for: .milliseconds(20)) }+ #expect(started == 2 && c.dragsRunning, "on again: it starts again")+ // Showing an already shown notch keeps the one monitor.+ c.show()+ #expect(started == 2)+ c.setShown(false)+ }}@Suite("Launch")