Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

Trust the Mac you sign in on; one remote-access switch (CUA-2278, CUA-2279) (#5934)

cua-agents[bot]566bc29af836
diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/MachinesViewTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/MachinesViewTests.swift
index 3bb425ca4e..835d20f927 100644
--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/MachinesViewTests.swift
+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/MachinesViewTests.swift
@@ -105,7 +105,7 @@ struct MachinesViewTests {
view.groups.flatMap(\.ids).contains(id)
})
let me = view.machines.first { $0.current }
- #expect(me?.toggles.map(\.label) == ["Provide Spaces", "Share this desktop"])
+ #expect(me?.toggles.map(\.label) == ["Let my other devices use this Mac"])
#expect(me?.toggles.allSatisfy(\.editable) == true)
#expect(view.summary.contains("online"))
// Another machine's switches are read-only.
diff --git a/apps/cua-spaces-web/src/__tests__/machines-page.test.tsx b/apps/cua-spaces-web/src/__tests__/machines-page.test.tsx
index bcff471eba..98db7e28d2 100644
--- a/apps/cua-spaces-web/src/__tests__/machines-page.test.tsx
+++ b/apps/cua-spaces-web/src/__tests__/machines-page.test.tsx
@@ -127,7 +127,7 @@ describe.skipIf(!wasmBuilt)("the Machines page (real routes, wasm core)", () =>
// This Mac: its switches change here.
let detail = await detailOf("Ada's MacBook Pro");
const switches = () => [...detail.querySelectorAll<HTMLElement>("[data-machine-toggle] [role=switch]")];
- expect(switches().map((s) => s.getAttribute("aria-disabled") === "true" || s.hasAttribute("data-disabled"))).toEqual([false, false]);
+ expect(switches().map((s) => s.getAttribute("aria-disabled") === "true" || s.hasAttribute("data-disabled"))).toEqual([false]);
// Another Mac: read-only, and where to change it.
select("studio");
diff --git a/apps/cua-spaces-web/src/bridge/adapters/demo/host-setup.ts b/apps/cua-spaces-web/src/bridge/adapters/demo/host-setup.ts
index 041f777865..69343968a8 100644
--- a/apps/cua-spaces-web/src/bridge/adapters/demo/host-setup.ts
+++ b/apps/cua-spaces-web/src/bridge/adapters/demo/host-setup.ts
@@ -36,7 +36,8 @@ export function demoHostSetupHandlers({ state, now, wait, emit, stepMs }: DemoCo
directUrl: direct ? `http://${request.direct ?? "0.0.0.0:3211"}` : null,
name: request.name?.trim() || "This Mac",
shareDesktop: request.shareDesktop ?? !spare,
- provideSpaces: !direct && (request.provideSpaces ?? spare),
+ // The default choice turns on the screen and Spaces; a direct connection only the screen.
+ provideSpaces: !direct && (request.provideSpaces ?? true),
permissions: state.host.permissions,
clients: [],
recentAccess: [],
diff --git a/apps/cua-spaces-web/src/bridge/derive.ts b/apps/cua-spaces-web/src/bridge/derive.ts
index 99a0753b47..8d02c05b5a 100644
--- a/apps/cua-spaces-web/src/bridge/derive.ts
+++ b/apps/cua-spaces-web/src/bridge/derive.ts
@@ -605,7 +605,7 @@ function fallbackPanel(s: HostStatus | null): HostPanelView {
const FALLBACK_INTRO =
"This is the computer you’re using now. Set it up so you, your teammates and your AI agents can use it from other devices. Cua connects them for you, with no network setup.";
const FALLBACK_CHOICES: HostSetupChoice[] = [
- { id: "desktop", label: "Use this computer from my other devices", buttonLabel: "Set Up…" },
+ { id: "desktop", label: "Let my other devices use this computer", buttonLabel: "Set Up…" },
{ id: "spare", label: "Run Spaces here and keep its screen private", buttonLabel: "Set Up…" },
];
diff --git a/apps/cua-spaces/src-tauri/tests/host_commands.rs b/apps/cua-spaces/src-tauri/tests/host_commands.rs
index 42a104fe41..e868bf60db 100644
--- a/apps/cua-spaces/src-tauri/tests/host_commands.rs
+++ b/apps/cua-spaces/src-tauri/tests/host_commands.rs
@@ -249,6 +249,8 @@ async fn cua_host_backend_runs_the_relay_flow_end_to_end() {
relay_url: Some(relay.url.clone()),
name: Some("Studio".into()),
allow: Some(vec!["[email protected]".into()]),
+ // Start with Spaces off to walk the off-to-on switch below.
+ provide_spaces: Some(false),
..Default::default()
})
.await
diff --git a/apps/cua-spaces/src/components/Onboarding.test.tsx b/apps/cua-spaces/src/components/Onboarding.test.tsx
index 53e9b1d021..5806f9121f 100644
--- a/apps/cua-spaces/src/components/Onboarding.test.tsx
+++ b/apps/cua-spaces/src/components/Onboarding.test.tsx
@@ -39,7 +39,7 @@ describe("Onboarding", () => {
render(<Onboarding host={host} onDone={onDone} identity="[email protected]" />);
fireEvent.click(screen.getByText("Let my other devices reach this Mac"));
fireEvent.click(screen.getByRole("button", { name: "Continue" }));
- expect(screen.getByText("You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].")).toBeInTheDocument();
+ expect(screen.getByText("You and the people you share with can see and use this computer’s screen, and create Spaces on it, from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].")).toBeInTheDocument();
// Direct ip:port is hidden until Advanced is opened.
expect(screen.queryByText(/Direct connection/)).toBeNull();
fireEvent.click(screen.getByRole("button", { name: "Turn on remote access" }));
diff --git a/apps/cua-spaces/src/native/host.ts b/apps/cua-spaces/src/native/host.ts
index 1b780e8924..4ecf9df4f4 100644
--- a/apps/cua-spaces/src/native/host.ts
+++ b/apps/cua-spaces/src/native/host.ts
@@ -224,7 +224,7 @@ export function createFakeHostBridge(
const spare = request.profile === "spare";
state.status = {
shareDesktop: request.shareDesktop ?? !spare,
- provideSpaces: request.provideSpaces ?? spare,
+ provideSpaces: request.provideSpaces ?? (request.mode !== "direct"),
maxSpaces: 4,
maxMacosVms: options.platform === "macos" ? 2 : 0,
providedSpaces: [],
diff --git a/libs/cua/crates/cua-cli/src/host.rs b/libs/cua/crates/cua-cli/src/host.rs
index 5b015adfa3..cb6450e8d0 100644
--- a/libs/cua/crates/cua-cli/src/host.rs
+++ b/libs/cua/crates/cua-cli/src/host.rs
@@ -1929,6 +1929,12 @@ pub async fn run_host(
Some(p) => p,
None => tokens,
};
+ if paired.is_none()
+ && let cua_host::HostMode::Relay { url } = &opts.mode
+ && let Ok(device) = crate::devices_cmd::device_auth(url)
+ {
+ opts.device_session = device.try_session().await;
+ }
let s = host
.setup_staged(opts, tokens)
.await
diff --git a/libs/cua/crates/cua-host/src/host.rs b/libs/cua/crates/cua-host/src/host.rs
index 0b66cf2535..a8fd7d7f67 100644
--- a/libs/cua/crates/cua-host/src/host.rs
+++ b/libs/cua/crates/cua-host/src/host.rs
@@ -124,6 +124,12 @@ pub struct SetupOptions {
/// (`kind = "machine"`), where they run with its GPU and drivers as
/// they are. Never for a computer you also use; default off.
pub dedicated: bool,
+ /// This device's relay session, when it is enrolled for the account
+ /// (relay mode). Registering with it is the proof the relay vouches
+ /// for ("an enrolled device's signature"), so the Mac the user just
+ /// signed in on is not listed as a new, unconfirmed computer. `None`
+ /// (not enrolled, or a pairing code) leaves the relay to flag it.
+ pub device_session: Option<String>,
}
/// A relay in static-token mode ([`SetupOptions::static_relay`]).
@@ -153,6 +159,7 @@ impl SetupOptions {
tailnet: false,
download_first: false,
dedicated: false,
+ device_session: None,
}
}
@@ -179,6 +186,7 @@ impl SetupOptions {
tailnet: false,
download_first: false,
dedicated: false,
+ device_session: None,
}
}
}
@@ -1311,6 +1319,9 @@ impl Host {
match &opts.mode {
HostMode::Relay { url } => {
let relay = RelayClient::new(url)?;
+ let relay_with_device = relay
+ .clone()
+ .with_device_session(opts.device_session.clone());
*stage = SetupStage::Token;
let token = tokens.access_token().await?;
*stage = SetupStage::Register;
@@ -1319,7 +1330,7 @@ impl Host {
// machine token; the account session is used only for this
// call and never stored under the host directory.
let current = read_secret(&self.paths.machine_token()).ok();
- let reg = relay
+ let reg = relay_with_device
.register_as_machine(
&token,
current.as_deref(),
diff --git a/libs/cua/crates/cua-host/src/setup_tests.rs b/libs/cua/crates/cua-host/src/setup_tests.rs
index 472852e45b..d874b95758 100644
--- a/libs/cua/crates/cua-host/src/setup_tests.rs
+++ b/libs/cua/crates/cua-host/src/setup_tests.rs
@@ -288,3 +288,43 @@ async fn a_pairing_code_sets_up_the_machine_once_and_a_failed_download_does_not_
assert_eq!(stage, SetupStage::Register);
assert_eq!(e.http_status(), Some(401), "{e}");
}
+
+/// The Mac the user just signed in on is enrolled by that sign-in, so its
+/// own host registration carries the device's session and is not listed as
+/// a new computer to confirm; one without the session still is.
+#[tokio::test]
+async fn a_signed_in_devices_own_registration_is_confirmed() {
+ let relay = FakeRelay::start().await;
+ relay.add_account("acct", "user-1", Some("[email protected]"));
+ relay.require_devices(true);
+ relay.fresh_sign_in("user-1");
+ let auth = DeviceAuth::new(
+ &relay.url,
+ Arc::new(StaticToken("acct".into())),
+ Arc::new(crate::device::MemoryKeySlot::default()),
+ "mini",
+ )
+ .unwrap();
+ auth.enroll().await.unwrap();
+ let session = auth.session().await.unwrap();
+ let account = StaticToken("acct".into());
+
+ let own = fixture();
+ let mut opts = own.opts(&relay.url);
+ opts.device_session = Some(session);
+ let status = own.host().setup(opts, &account).await.unwrap();
+ let id = status.machine_id.unwrap();
+ assert!(relay.machine(&id).unwrap().confirmed);
+
+ let unproven = fixture();
+ let status = unproven
+ .host()
+ .setup(unproven.opts(&relay.url), &account)
+ .await
+ .unwrap();
+ let id = status.machine_id.unwrap();
+ assert!(
+ !relay.machine(&id).unwrap().confirmed,
+ "no device proof keeps the warning"
+ );
+}
diff --git a/libs/cua/crates/cua-host/src/testing.rs b/libs/cua/crates/cua-host/src/testing.rs
index 65dff0c3db..39ec75bcb6 100644
--- a/libs/cua/crates/cua-host/src/testing.rs
+++ b/libs/cua/crates/cua-host/src/testing.rs
@@ -375,10 +375,11 @@ async fn register(
viewers: vec![],
clients: vec![],
host,
- // This mock never asks for a device signature or MFA, so a
- // registration here has nothing to vouch for either way; default to
- // confirmed, matching behavior before S5 added the field.
- confirmed: true,
+ // Like the real relay once devices are required: only a
+ // registration carrying an enrolled device's session is proven.
+ // Otherwise (devices not required) there is nothing to vouch for
+ // either way, so it is confirmed, as before S5 added the field.
+ confirmed: !st.require_devices || st.device_of(&headers, &who).is_some(),
team: None,
meta: body["meta"]
.as_object()
diff --git a/libs/cua/crates/cua-sdk/src/native/host.rs b/libs/cua/crates/cua-sdk/src/native/host.rs
index 4461666ea3..52d642005f 100644
--- a/libs/cua/crates/cua-sdk/src/native/host.rs
+++ b/libs/cua/crates/cua-sdk/src/native/host.rs
@@ -223,6 +223,18 @@ impl Relay {
}
}
+/// This device's session on the relay at `url`, when it is enrolled there
+/// (`None` otherwise: the relay then decides what it trusts).
+async fn own_device_session(url: &str) -> Option<String> {
+ let session = Arc::new(cua_auth::Session::from_env());
+ let store = session.store().clone();
+ let tokens = Arc::new(SessionTokens(session));
+ cua_host::DeviceAuth::new(url, tokens, Arc::new(store), cua_host::device_name())
+ .ok()?
+ .try_session()
+ .await
+}
+
#[uniffi::export]
impl Relay {
/// A relay (`None` = the relay `cua` uses: `CUA_RELAY_URL`, else this
@@ -706,6 +718,15 @@ impl Host {
let (r, failed_stage, http_status) = match opts {
Ok(opts) => {
let staged = run(async move {
+ let mut opts = opts;
+ // The Mac the user signed in on is enrolled by that
+ // sign-in: registering with its session is the proof
+ // the relay needs not to flag it as a new computer.
+ if let (cua_host::HostMode::Relay { url }, Some(_)) =
+ (&opts.mode, account_token.as_ref())
+ {
+ opts.device_session = own_device_session(url).await;
+ }
let host = cua_host::Host::new(home);
let staged = match account_token {
Some(t) => host.setup_staged(opts, &cua_host::StaticToken(t)).await,
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/machines.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/machines.json
index f59f023dda..c44a38c3ec 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/machines.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/machines.json
@@ -89,8 +89,7 @@
"pages": [
[
"Ada's MacBook Pro — Online (rename: host)",
- "Provide Spaces: off (runs: provide-spaces)",
- "Share this desktop: on (runs: hide-desktop)",
+ "Let my other devices use this Mac: on (runs: stop-sharing)",
"desktop This Mac · macOS · This Mac [Desktop] -> this-mac",
"space space-cdf71481c4 · macOS 26.5.2 · Running -> local:space-cdf71481c4",
"space space-1cef393ac1 · Linux · Suspended -> local:space-1cef393ac1",
@@ -135,7 +134,7 @@
"Share this desktop: off (read-only)",
"note: Change this on that PC.",
"spaces: No Spaces yet.",
- "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on Provide Spaces on that PC.)",
+ "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on “Let my other devices use this PC” on that PC.)",
"details: OS: Windows",
"Remove from account -> dev_lap"
],
@@ -182,8 +181,7 @@
"pages": [
[
"Ada's MacBook Pro — Online (rename: host)",
- "Provide Spaces: off (runs: hide-desktop, resume-sharing)",
- "Share this desktop: off (runs: stop-providing-spaces, resume-sharing)",
+ "Let my other devices use this Mac: off (runs: resume-sharing)",
"space space-cdf71481c4 · macOS 26.5.2 · Running -> local:space-cdf71481c4",
"space space-1cef393ac1 · Linux · Suspended -> local:space-1cef393ac1",
"New Space here on local",
@@ -206,7 +204,7 @@
"Share this desktop: off (read-only)",
"note: Change this on that PC.",
"spaces: No Spaces yet.",
- "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on Provide Spaces on that PC.)",
+ "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on “Let my other devices use this PC” on that PC.)",
"details: OS: Windows",
"Remove from account -> dev_lap"
],
@@ -236,8 +234,7 @@
"pages": [
[
"Ada's MacBook Pro — Online",
- "Provide Spaces: off (sets up: spare)",
- "Share this desktop: off (sets up: desktop)",
+ "Let my other devices use this Mac: off (sets up: desktop)",
"spaces: No Spaces yet.",
"New Space here on local",
"details: OS: macOS 26.5.2; App: 0.9.1; Connection: Not shared"
@@ -276,8 +273,7 @@
"Ada's MacBook Pro — Online (rename: host)",
"issues fail: Cua can’t reach this Mac’s macOS Spaces: Local Network access is off for Cua Spaces. [Open Local Network settings]",
"issues warn: Only 21 GB free. A macOS Space needs about 30 GB. [Free disk space]",
- "Provide Spaces: off (runs: provide-spaces)",
- "Share this desktop: on (runs: hide-desktop)",
+ "Let my other devices use this Mac: on (runs: stop-sharing)",
"desktop This Mac · macOS · This Mac [Desktop] -> this-mac",
"space space-cdf71481c4 · macOS 26.5.2 · Running -> local:space-cdf71481c4",
"space space-1cef393ac1 · Linux · Suspended -> local:space-1cef393ac1",
@@ -324,7 +320,7 @@
"Share this desktop: off (read-only)",
"note: Change this on that PC.",
"spaces: No Spaces yet.",
- "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on Provide Spaces on that PC.)",
+ "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on “Let my other devices use this PC” on that PC.)",
"details: OS: Windows",
"Remove from account -> dev_lap"
],
@@ -381,8 +377,7 @@
"Ada's MacBook Pro — Online (rename: host)",
"issues fail: Cua can’t reach this Mac’s macOS Spaces: Local Network access is off for Cua Spaces. [Open Local Network settings]",
"issues warn: Only 21 GB free. A macOS Space needs about 30 GB. [Free disk space]",
- "Provide Spaces: off (runs: provide-spaces)",
- "Share this desktop: on (runs: hide-desktop)",
+ "Let my other devices use this Mac: on (runs: stop-sharing)",
"desktop This Mac · macOS · This Mac [Desktop] -> this-mac",
"space space-cdf71481c4 · macOS 26.5.2 · Running -> local:space-cdf71481c4",
"space space-1cef393ac1 · Linux · Suspended -> local:space-1cef393ac1",
@@ -429,7 +424,7 @@
"Share this desktop: off (read-only)",
"note: Change this on that PC.",
"spaces: No Spaces yet.",
- "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on Provide Spaces on that PC.)",
+ "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on “Let my other devices use this PC” on that PC.)",
"details: OS: Windows",
"Remove from account -> dev_lap"
],
@@ -486,8 +481,7 @@
"Ada's MacBook Pro — Online (rename: host)",
"issues fail: Cua can’t reach this Mac’s macOS Spaces: Local Network access is off for Cua Spaces. [Open Local Network settings]",
"issues warn: Only 21 GB free. A macOS Space needs about 30 GB. [Free disk space]",
- "Provide Spaces: off (runs: provide-spaces)",
- "Share this desktop: on (runs: hide-desktop)",
+ "Let my other devices use this Mac: on (runs: stop-sharing)",
"desktop This Mac · macOS · This Mac [Desktop] -> this-mac",
"space space-cdf71481c4 · macOS 26.5.2 · Running -> local:space-cdf71481c4",
"space space-1cef393ac1 · Linux · Suspended -> local:space-1cef393ac1",
@@ -534,7 +528,7 @@
"Share this desktop: off (read-only)",
"note: Change this on that PC.",
"spaces: No Spaces yet.",
- "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on Provide Spaces on that PC.)",
+ "New Space here on host:dev_lap (disabled: It doesn’t provide Spaces. Turn on “Let my other devices use this PC” on that PC.)",
"details: OS: Windows",
"Remove from account -> dev_lap"
],
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/main-window.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/main-window.json
index e9f48406a3..04afa41e3c 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/main-window.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/main-window.json
@@ -187,7 +187,7 @@
"System: macOS"
],
"isHost": true,
- "previewText": "This is this Mac’s own screen, so it isn’t shown here. Your other devices see and control it while Share this desktop is on.",
+ "previewText": "This is this Mac’s own screen, so it isn’t shown here. Your other devices see and control it while you let them use it.",
"sections": [],
"title": "This computer"
}
@@ -324,7 +324,7 @@
"profile: Use it to [-] = desktop",
"allow: Share with (optional) [Teammates’ emails] = "
],
- "lede": "You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
+ "lede": "You and the people you share with can see and use this computer’s screen, and create Spaces on it, from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
"request": "mode=relay relay=- direct=- name=- allow=-",
"title": "Set up this computer"
},
@@ -342,7 +342,7 @@
"profile: Use it to [-] = desktop",
"allow: Share with (optional) [Teammates’ emails] = "
],
- "lede": "You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
+ "lede": "You and the people you share with can see and use this computer’s screen, and create Spaces on it, from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
"request": "mode=relay relay=- direct=- name=Studio allow=-",
"title": "Set up this computer"
},
@@ -360,7 +360,7 @@
"profile: Use it to [-] = desktop",
"allow: Share with (optional) [Teammates’ emails] = [email protected], [email protected]"
],
- "lede": "You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
+ "lede": "You and the people you share with can see and use this computer’s screen, and create Spaces on it, from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
"request": "mode=relay relay=- direct=- name=Studio [email protected],[email protected]",
"title": "Set up this computer"
},
@@ -548,7 +548,7 @@
"profile: Use it to [-] = desktop",
"allow: Share with (optional) [Teammates’ emails] = [email protected], [email protected]"
],
- "lede": "You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
+ "lede": "You and the people you share with can see and use this computer’s screen, and create Spaces on it, from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
"request": "mode=relay relay=https://relay.example direct=- name=Studio [email protected],[email protected]",
"title": "Set up this computer"
},
@@ -566,7 +566,7 @@
"profile: Use it to [-] = desktop",
"allow: Share with (optional) [Teammates’ emails] = [email protected], [email protected]"
],
- "lede": "You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
+ "lede": "You and the people you share with can see and use this computer’s screen, and create Spaces on it, from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
"request": "mode=relay relay=https://relay.example direct=- name=Studio [email protected],[email protected]",
"title": "Set up this computer"
},
diff --git a/libs/cua/crates/cua-spaces-app-core/src/host.rs b/libs/cua/crates/cua-spaces-app-core/src/host.rs
index 3c8a073780..7e8547bbc5 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/host.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/host.rs
@@ -225,11 +225,14 @@ pub struct HostSetupRequest {
impl HostSetupRequest {
/// `(share_desktop, provide_spaces)` the request asks for: the
- /// profile's, then each explicit setting.
+ /// profile's, then each explicit setting. The default profile is one
+ /// choice, "let my other devices use this computer": its screen and
+ /// Spaces (Spaces need the relay, so a direct connection shares only
+ /// the screen).
pub fn settings(&self) -> (bool, bool) {
let (mut desktop, mut provide) = match self.profile.as_deref() {
Some("spare") => (false, true),
- _ => (true, false),
+ _ => (true, self.mode.trim() != "direct"),
};
if let Some(d) = self.share_desktop {
desktop = d;
@@ -1054,7 +1057,7 @@ it up so you, your teammates and your AI agents can use it from other devices. \
Cua connects them for you, with no network setup.";
/// The "Use it to" option that shares this computer's screen.
-pub const DESKTOP_CHOICE: &str = "Use this computer from my other devices";
+pub const DESKTOP_CHOICE: &str = "Let my other devices use this computer";
/// The "Use it to" option for a spare computer that only runs Spaces.
pub const SPARE_CHOICE: &str = "Run Spaces here and keep its screen private";
/// The button that sets this computer up (shares its screen).
@@ -1814,7 +1817,7 @@ pub fn form_view(s: &HostFormState, identity: Option<&str>) -> HostFormView {
let what = if s.spare {
"This computer runs Spaces, separate computers inside it, that you and your team open from other devices. Its own screen stays private."
} else {
- "You and the people you share with can see and use this computer\u{2019}s screen from other devices. Cua connects them for you, with no network setup."
+ "You and the people you share with can see and use this computer\u{2019}s screen, and create Spaces on it, from other devices. Cua connects them for you, with no network setup."
};
match identity.filter(|i| !i.is_empty()) {
_ if s.advanced => {
@@ -2712,6 +2715,28 @@ mod tests {
assert_eq!(v.request.unwrap().settings(), (true, false));
}
+ #[test]
+ fn the_default_choice_turns_on_everything_remote_access_needs() {
+ let relay = validate_setup(HostSetupRequest {
+ mode: "relay".into(),
+ ..Default::default()
+ })
+ .unwrap();
+ assert_eq!(relay.settings(), (true, true));
+ let direct = validate_setup(HostSetupRequest {
+ mode: "direct".into(),
+ direct: Some("0.0.0.0:3211".into()),
+ ..Default::default()
+ })
+ .unwrap();
+ assert_eq!(direct.settings(), (true, false));
+ // The form's one choice asks for both.
+ assert_eq!(
+ form_view(&form_initial(), None).request.unwrap().settings(),
+ (true, true)
+ );
+ }
+
#[test]
fn setup_settings_are_validated() {
let spare = validate_setup(HostSetupRequest {
@@ -2730,6 +2755,7 @@ mod tests {
HostSetupRequest {
mode: "relay".into(),
share_desktop: Some(false),
+ provide_spaces: Some(false),
..Default::default()
},
HostSetupRequest {
diff --git a/libs/cua/crates/cua-spaces-app-core/src/machines_view.rs b/libs/cua/crates/cua-spaces-app-core/src/machines_view.rs
index eef92b5dcf..df62d6e055 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/machines_view.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/machines_view.rs
@@ -4,7 +4,7 @@
//! The Machines page as every UI draws it: the list in groups ("Your
//! machines", a collapsed "Offline for 30+ days", "Team machines"), one
//! muted line per row, and each machine's page (its name and rename, the
-//! Provide Spaces and Share this desktop switches, the Spaces on it as
+//! one "Let my other devices use this computer" switch, the Spaces on it as
//! links, New Space here, Details, and Remove from account).
//!
//! The page is about the hardware. Opening, starting, stopping, teleporting
@@ -430,107 +430,76 @@ struct Switches {
share: bool,
}
-/// This machine's switches, from its host state.
-fn host_toggles(s: Option<&HostState>) -> Vec<MachinesViewToggle> {
- let provide_help = "Your devices can create Spaces here.";
- let share_help = "Your devices can see and control this screen.";
+/// "this Mac", "this PC", "this computer".
+pub(crate) fn this_machine(os: &str) -> &'static str {
+ match os {
+ "macos" => "this Mac",
+ "windows" => "this PC",
+ _ => "this computer",
+ }
+}
+
+/// The one remote-access switch on a machine's page, in plain words:
+/// "Let my other devices use this Mac".
+pub(crate) fn remote_label(os: &str) -> String {
+ format!("Let my other devices use {}", this_machine(os))
+}
+
+/// This machine's switch, from its host state: one choice that lets your
+/// other devices see and control its screen and create Spaces on it.
+/// Turning it on turns on everything that takes; turning it off stops
+/// sharing, so it reads as off (and the two settings underneath stay as
+/// they were).
+fn host_toggles(s: Option<&HostState>, os: &str) -> Vec<MachinesViewToggle> {
+ let help = "They can see and control this screen and create Spaces here.";
let Some(s) = s.filter(|s| s.configured) else {
- // Before setup: either switch opens the setup form.
- let loading = s.is_none();
- return vec![
- MachinesViewToggle {
- id: "spaces".into(),
- label: "Provide Spaces".into(),
- help: provide_help.into(),
- on: false,
- editable: true,
- enabled: !loading,
- actions: vec![],
- setup: Some("spare".into()),
- },
- MachinesViewToggle {
- id: "desktop".into(),
- label: "Share this desktop".into(),
- help: share_help.into(),
- on: false,
- editable: true,
- enabled: !loading,
- actions: vec![],
- setup: Some("desktop".into()),
- },
- ];
+ // Before setup: the switch opens the setup form.
+ return vec![MachinesViewToggle {
+ id: "remote".into(),
+ label: remote_label(os),
+ help: help.into(),
+ on: false,
+ editable: true,
+ enabled: s.is_some(),
+ actions: vec![],
+ setup: Some("desktop".into()),
+ }];
};
let relay = s.mode.as_deref() != Some("direct");
- // Stopped sharing reads as both switches off: the switches are the one
- // control, so there is no separate "Not sharing" card to reconcile.
+ // Stopped sharing reads as the switch off: it is the one control, so
+ // there is no separate "Not sharing" card to reconcile.
let live = s.sharing || s.paused_signed_out;
- let provide_on = s.provide_spaces && live;
- let share_on = s.share_desktop && live;
- let flip = |on: bool,
- setting: bool,
- turn_on: HostActionId,
- turn_off: HostActionId,
- other_setting: bool,
- other_off: HostActionId| {
- if on {
- return vec![turn_off];
- }
+ let on = (s.share_desktop || s.provide_spaces) && live;
+ let actions = if on {
+ vec![HostActionId::StopSharing]
+ } else {
let mut a = vec![];
- if !setting {
- a.push(turn_on);
+ if !s.share_desktop {
+ a.push(HostActionId::ShareDesktop);
}
- if !s.sharing && !s.paused_signed_out {
- // Resuming turns on every setting that is on: keep the other
- // one off, as its switch shows it.
- if other_setting {
- a.push(other_off);
- }
+ // Spaces need the relay; a direct host only shares its screen.
+ if relay && !s.provide_spaces {
+ a.push(HostActionId::ProvideSpaces);
+ }
+ if !live {
a.push(HostActionId::ResumeSharing);
}
a
};
- let enabled = relay && !s.paused_signed_out;
- let provide_help = if relay {
- provide_help
- } else {
- "Needs the relay."
- };
- vec![
- MachinesViewToggle {
- id: "spaces".into(),
- label: "Provide Spaces".into(),
- help: provide_help.into(),
- on: provide_on,
- editable: true,
- enabled,
- actions: flip(
- provide_on,
- s.provide_spaces,
- HostActionId::ProvideSpaces,
- HostActionId::StopProvidingSpaces,
- s.share_desktop,
- HostActionId::HideDesktop,
- ),
- setup: None,
- },
- MachinesViewToggle {
- id: "desktop".into(),
- label: "Share this desktop".into(),
- help: share_help.into(),
- on: share_on,
- editable: true,
- enabled,
- actions: flip(
- share_on,
- s.share_desktop,
- HostActionId::ShareDesktop,
- HostActionId::HideDesktop,
- s.provide_spaces,
- HostActionId::StopProvidingSpaces,
- ),
- setup: None,
+ vec![MachinesViewToggle {
+ id: "remote".into(),
+ label: remote_label(os),
+ help: if relay {
+ help.into()
+ } else {
+ "They can see and control this screen.".into()
},
- ]
+ on,
+ editable: true,
+ enabled: !s.paused_signed_out,
+ actions,
+ setup: None,
+ }]
}
/// Another machine's switches: read-only, showing what it does.
@@ -734,7 +703,7 @@ pub fn view(input: &MachinesViewInput) -> MachinesView {
};
let toggles = if row.current {
- host_toggles(host)
+ host_toggles(host, &row.os)
} else {
remote_toggles(&sw, team)
};
@@ -767,7 +736,8 @@ pub fn view(input: &MachinesViewInput) -> MachinesView {
Some("It isn\u{2019}t sharing.".into())
} else if !sw.provide {
Some(format!(
- "It doesn\u{2019}t provide Spaces. Turn on Provide Spaces on {}.",
+ "It doesn\u{2019}t provide Spaces. Turn on \u{201c}{}\u{201d} on {}.",
+ remote_label(&row.os),
that_machine(&row.os)
))
} else {
@@ -1262,15 +1232,10 @@ mod tests {
.iter()
.map(|t| (t.label.as_str(), t.on, t.editable && t.enabled))
.collect();
- assert_eq!(
- t,
- [
- ("Provide Spaces", false, true),
- ("Share this desktop", true, true)
- ]
- );
- assert_eq!(me.toggles[0].actions, [HostActionId::ProvideSpaces]);
- assert_eq!(me.toggles[1].actions, [HostActionId::HideDesktop]);
+ // One plain choice, on while anything is shared; off stops sharing.
+ assert_eq!(t, [("Let my other devices use this Mac", true, true)]);
+ assert_eq!(me.toggles[0].id, "remote");
+ assert_eq!(me.toggles[0].actions, [HostActionId::StopSharing]);
assert_eq!(me.toggles_note, None);
let studio = by_id(&v, "studio");
@@ -1300,7 +1265,7 @@ mod tests {
}
#[test]
- fn stopped_sharing_reads_as_switches_off_and_turning_one_on_resumes() {
+ fn stopped_sharing_reads_as_the_switch_off_and_turning_one_on_resumes() {
let mut input = mockup();
input.host = Some(HostState {
sharing: false,
@@ -1309,16 +1274,47 @@ mod tests {
let v = view(&input);
let me = by_id(&v, "this-mac");
assert!(me.toggles.iter().all(|t| !t.on && t.enabled));
- // Turning Provide Spaces on resumes sharing, keeping the desktop off
- // as its switch shows.
- assert_eq!(
- me.toggles[0].actions,
- [HostActionId::HideDesktop, HostActionId::ResumeSharing]
- );
+ // Turning it on resumes sharing (both settings are already on).
+ assert_eq!(me.toggles[0].actions, [HostActionId::ResumeSharing]);
// No "Not sharing" card: the switches are the one control.
assert_eq!(me.notice, None);
}
+ #[test]
+ fn turning_the_one_switch_on_turns_on_everything_it_needs() {
+ let me = |h: HostState| {
+ let mut input = mockup();
+ input.host = Some(h);
+ by_id(&view(&input), "this-mac").toggles[0].clone()
+ };
+ // Nothing shared: the screen and Spaces both come on.
+ let t = me(HostState {
+ share_desktop: false,
+ provide_spaces: false,
+ ..host(false, false)
+ });
+ assert!(!t.on);
+ assert_eq!(
+ t.actions,
+ [HostActionId::ShareDesktop, HostActionId::ProvideSpaces]
+ );
+ // Stopped, and only the screen was on: Spaces come on, then it resumes.
+ let t = me(HostState {
+ sharing: false,
+ ..host(false, true)
+ });
+ assert_eq!(
+ t.actions,
+ [HostActionId::ProvideSpaces, HostActionId::ResumeSharing]
+ );
+ // A direct connection can only share the screen.
+ let t = me(HostState {
+ mode: Some("direct".into()),
+ ..host(false, false)
+ });
+ assert_eq!(t.actions, [HostActionId::ShareDesktop]);
+ }
+
#[test]
fn before_setup_a_switch_opens_the_setup_form() {
let mut input = mockup();
@@ -1330,8 +1326,9 @@ mod tests {
.iter()
.map(|t| t.setup.as_deref())
.collect::<Vec<_>>(),
- [Some("spare"), Some("desktop")]
+ [Some("desktop")]
);
+ assert_eq!(me.toggles[0].label, "Let my other devices use this Mac");
assert!(me.remove.is_none() && me.rename.is_none());
assert_eq!(me.name, "Ada's MacBook Pro");
}
diff --git a/libs/cua/crates/cua-spaces-app-core/src/spaces/sidebar.rs b/libs/cua/crates/cua-spaces-app-core/src/spaces/sidebar.rs
index 1c0f0bf387..a657cb047b 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/spaces/sidebar.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/spaces/sidebar.rs
@@ -580,7 +580,7 @@ pub fn desktop_note(space: &Space) -> Option<String> {
pub fn host_desktop_note(os: crate::model::SpaceOs) -> String {
format!(
"This is {}\u{2019}s own screen, so it isn\u{2019}t shown here. \
- Your other devices see and control it while Share this desktop is on.",
+ Your other devices see and control it while you let them use it.",
os.this_machine_lower()
)
}
diff --git a/libs/cua/crates/cua-spaces-ffi/src/app_core.rs b/libs/cua/crates/cua-spaces-ffi/src/app_core.rs
index 032a989e8a..2a045457da 100644
--- a/libs/cua/crates/cua-spaces-ffi/src/app_core.rs
+++ b/libs/cua/crates/cua-spaces-ffi/src/app_core.rs
@@ -2940,6 +2940,10 @@ pub(crate) fn setup_options_for_request(
request: AppHostSetupRequest,
) -> Result<cua_sdk::HostSetupOptions> {
let request = core::host::validate_setup(request).map_err(CuaError::InvalidArgument)?;
+ // The default choice is "let my other devices use this computer": its
+ // screen and Spaces. Pass what the core resolved, not the SDK's own
+ // (CLI) profile defaults, so both agree.
+ let (share_desktop, provide_spaces) = request.settings();
Ok(cua_sdk::HostSetupOptions {
mode: Some(request.mode),
relay_url: request.relay_url,
@@ -2949,8 +2953,8 @@ pub(crate) fn setup_options_for_request(
driver_bin: None,
runner: None,
profile: request.profile,
- share_desktop: request.share_desktop,
- provide_spaces: request.provide_spaces,
+ share_desktop: Some(share_desktop),
+ provide_spaces: Some(provide_spaces),
})
}
@@ -3004,6 +3008,31 @@ mod host_setup_tests {
})
.unwrap();
assert_eq!(o.profile.as_deref(), Some("spare"));
+ assert_eq!(
+ (o.share_desktop, o.provide_spaces),
+ (Some(false), Some(true))
+ );
+ // The default choice, "let my other devices use this computer",
+ // turns on the screen and Spaces; a direct connection only the screen.
+ let o = setup_options_for_request(AppHostSetupRequest {
+ mode: "relay".into(),
+ ..Default::default()
+ })
+ .unwrap();
+ assert_eq!(
+ (o.share_desktop, o.provide_spaces),
+ (Some(true), Some(true))
+ );
+ let o = setup_options_for_request(AppHostSetupRequest {
+ mode: "direct".into(),
+ direct: Some("10.0.0.2:4000".into()),
+ ..Default::default()
+ })
+ .unwrap();
+ assert_eq!(
+ (o.share_desktop, o.provide_spaces),
+ (Some(true), Some(false))
+ );
}
}