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.

fix(spaces-desktop): keep automatic updates on for people moved from the Mac app (#5185)

ddupontd33e5f5a9e6b
diff --git a/apps/cua-spaces-desktop/docs/sparkle-cutover.md b/apps/cua-spaces-desktop/docs/sparkle-cutover.md
index d766528a9f..c9145bf443 100644
--- a/apps/cua-spaces-desktop/docs/sparkle-cutover.md
+++ b/apps/cua-spaces-desktop/docs/sparkle-cutover.md
@@ -79,9 +79,15 @@ Those are the rehearsal below.
beta feed has worked end to end: a beta updated to the next beta.
2. `STABLE_FEED = true` in `src/updater.ts`. The workflow refuses the
cutover otherwise.
-3. Migrated users update on their own. The updater counts as enabled when
+3. Migrated users update on their own (`src/update-prefs.ts`, done). Until
+ the user chooses in Settings → About, automatic checks are on when
`swiftMigration.found` is true and `sparkleAutomaticChecks !== false`
- (Sparkle's default was on). Everyone else stays opt-in.
+ (the Swift app's Info.plist turns Sparkle's checks on, so the key is only
+ saved when the user changed it), and automatic installs follow
+ `sparkleAutomaticDownloads`. A channel carried over from the Swift app
+ that isn't served to the Electron app on macOS (Stable, before
+ `STABLE_FEED`) falls back to the build's channel. Everyone else stays
+ opt-in.
4. electron-builder sets `generateUpdatesFilesForAllChannels: true` from the
cutover on. Stable releases then also write `beta*.yml`, so betas move
on to the stable release.
diff --git a/apps/cua-spaces-desktop/src/migrate-swift.ts b/apps/cua-spaces-desktop/src/migrate-swift.ts
index 764cc1e3f8..d094b51c32 100644
--- a/apps/cua-spaces-desktop/src/migrate-swift.ts
+++ b/apps/cua-spaces-desktop/src/migrate-swift.ts
@@ -19,7 +19,8 @@
// - The defaults domain com.trycua.spaces.macos: the window frame
// ("NSWindow Frame CuaSpacesWebUI") becomes `windowBounds`; Sparkle's
// SUEnableAutomaticChecks / SUAutomaticallyUpdate are recorded in the
-// marker (the cutover reads them) but turn nothing on. The rest is the
+// marker, and the updater follows them until the user chooses in this app
+// (update-prefs.ts: checks stay on unless they were off). The rest is the
// Swift window's colour cache (WebUIBackground*), its native video switch
// (WebUINativeVideo) and Sparkle's bookkeeping, none of which applies here.
// - ~/.cua is shared by both apps and needs nothing.
diff --git a/apps/cua-spaces-desktop/src/settings.ts b/apps/cua-spaces-desktop/src/settings.ts
index cdd9c6acb5..50e4174edb 100644
--- a/apps/cua-spaces-desktop/src/settings.ts
+++ b/apps/cua-spaces-desktop/src/settings.ts
@@ -31,14 +31,16 @@ export interface SwiftMigration {
export interface Settings {
windowBounds?: WindowBounds;
themeSource?: ThemeSource;
- /** Automatic update checks: opt-in; see updater.ts. */
+ /** Automatic update checks, as chosen in this app (unset: see update-prefs.ts). */
autoUpdate?: boolean;
- /** Download and install updates on their own (Settings → About). */
+ /** Download and install updates on their own (Settings → About; unset: see update-prefs.ts). */
autoInstall?: boolean;
/** The last update check (ms). */
lastUpdateCheck?: number;
/** Update channel; defaults to the one the build was cut for (see updater.ts). */
updateChannel?: "stable" | "beta";
+ /** The channel was picked in this app (Settings → About), not carried over from the Swift app. */
+ updateChannelChosen?: boolean;
/** Where the last picture-in-picture panel was left (pip.ts). */
pipBounds?: { x: number; y: number; width: number; height: number };
/** Where the last Space viewer was left, and its content's width (viewer.ts). */
diff --git a/apps/cua-spaces-desktop/src/update-prefs.ts b/apps/cua-spaces-desktop/src/update-prefs.ts
new file mode 100644
index 0000000000..1aedbc0119
--- /dev/null
+++ b/apps/cua-spaces-desktop/src/update-prefs.ts
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+// What the updater (updater.ts) does when the user hasn't chosen in this
+// app. Kept free of Electron so it can be tested on its own.
+//
+// Someone who moved over from the Swift app (migrate-swift.ts) keeps what
+// Sparkle did for them there: automatic checks stay on unless they had turned
+// them off (the Swift app's Info.plist sets SUEnableAutomaticChecks, so the
+// defaults domain only holds the key when the user changed it), and
+// automatic installs stay as they had them. Everyone else stays opt-in.
+import type { Settings } from "./settings";
+
+export type UpdateChannel = "stable" | "beta";
+
+const movedFromSwift = (s: Settings) => s.swiftMigration?.found === true;
+
+/** Automatic checks: the choice made in this app, else the one carried over from Sparkle, else off. */
+export function autoCheckPref(s: Settings, env: NodeJS.ProcessEnv = {}): boolean {
+ if (env.CUA_SPACES_AUTO_UPDATE === "1") return true;
+ if (typeof s.autoUpdate === "boolean") return s.autoUpdate;
+ return movedFromSwift(s) && s.swiftMigration?.sparkleAutomaticChecks !== false;
+}
+
+/** Automatic installs: the choice made in this app, else the one carried over from Sparkle (off by default there too). */
+export function autoInstallPref(s: Settings): boolean {
+ if (typeof s.autoInstall === "boolean") return s.autoInstall;
+ return movedFromSwift(s) && s.swiftMigration?.sparkleAutomaticDownloads === true;
+}
+
+/**
+ * The channel to update from. A channel chosen in this app is kept as it
+ * is. One carried over from the Swift app that this app can't be served on
+ * this platform (Stable on macOS before the Sparkle cutover) would mean no
+ * updates at all, so the build's own channel is used instead.
+ */
+export function channelPref(s: Settings, build: UpdateChannel, served: (channel: UpdateChannel) => boolean): UpdateChannel {
+ const saved = s.updateChannel;
+ if (!saved) return build;
+ if (s.updateChannelChosen || served(saved)) return saved;
+ return build;
+}
diff --git a/apps/cua-spaces-desktop/src/updater.ts b/apps/cua-spaces-desktop/src/updater.ts
index d023aa98cc..3fbdeb308e 100644
--- a/apps/cua-spaces-desktop/src/updater.ts
+++ b/apps/cua-spaces-desktop/src/updater.ts
@@ -10,7 +10,9 @@
//
// Opt-in: nothing checks on its own unless the user turns automatic checks
// on (Settings → About, `"autoUpdate": true` in settings.json, or
-// CUA_SPACES_AUTO_UPDATE=1). The beta channel (prereleases, `beta*.yml`) is
+// CUA_SPACES_AUTO_UPDATE=1). Someone who moved over from the Swift app keeps
+// Sparkle's choices instead (update-prefs.ts): checks on unless they had
+// turned them off there. The beta channel (prereleases, `beta*.yml`) is
// served everywhere. The stable channel (`latest*.yml`) is served on Windows
// and Linux, where stable releases ship the Electron app. On macOS stable
// releases still ship the Swift app, updated by Sparkle; Check Now on Stable
@@ -23,18 +25,18 @@ import { electronUpdater } from "./electron-updater";
import { recordUpdateChannel } from "./mesh-channel";
import type { UpdaterDriving } from "./model/updates";
import { readSettings, writeSettings } from "./settings";
+import { autoCheckPref, autoInstallPref, channelPref, type UpdateChannel } from "./update-prefs";
+
+export type { UpdateChannel } from "./update-prefs";
const POLL_MS = 4 * 60 * 60 * 1000;
/** macOS only: off until stable releases publish the Electron macOS feed (the cutover). */
export const STABLE_FEED = false;
-export type UpdateChannel = "stable" | "beta";
-
/** The channel a version was cut for: X.Y.Z-suffix is a beta. */
export const buildChannel = (version = app.getVersion()): UpdateChannel => (/^\d+\.\d+\.\d+-/.test(version) ? "beta" : "stable");
-export const updateChannel = (): UpdateChannel => readSettings().updateChannel ?? buildChannel();
/** The feed file electron-updater reads: `beta*.yml` or `latest*.yml`. */
export const feedChannel = (channel: UpdateChannel) => (channel === "beta" ? "beta" : "latest");
@@ -46,11 +48,13 @@ export const channelServed = (
platform: NodeJS.Platform = process.platform,
) => channel === "beta" || stableFeed || platform === "win32" || platform === "linux";
+export const updateChannel = (): UpdateChannel => channelPref(readSettings(), buildChannel(), (c) => channelServed(c));
+
/** A packaged build with a feed (electron-builder's app-update.yml); a development run has no updater. */
export const hasFeed = () => app.isPackaged && existsSync(path.join(process.resourcesPath, "app-update.yml"));
export const updatesEnabled = () =>
- app.isPackaged && (process.env.CUA_SPACES_AUTO_UPDATE === "1" || readSettings().autoUpdate === true) && channelServed(updateChannel());
+ app.isPackaged && autoCheckPref(readSettings(), process.env) && channelServed(updateChannel());
type AutoUpdater = (typeof import("electron-updater"))["autoUpdater"];
@@ -88,7 +92,7 @@ export class ElectronUpdater implements UpdaterDriving {
}
get automaticallyChecks(): boolean {
- return process.env.CUA_SPACES_AUTO_UPDATE === "1" || readSettings().autoUpdate === true;
+ return autoCheckPref(readSettings(), process.env);
}
set automaticallyChecks(on: boolean) {
writeSettings({ autoUpdate: on });
@@ -97,7 +101,7 @@ export class ElectronUpdater implements UpdaterDriving {
}
get automaticallyInstalls(): boolean {
- return readSettings().autoInstall === true;
+ return autoInstallPref(readSettings());
}
set automaticallyInstalls(on: boolean) {
writeSettings({ autoInstall: on });
@@ -117,8 +121,9 @@ export class ElectronUpdater implements UpdaterDriving {
return updateChannel();
}
set channel(channel: UpdateChannel) {
- if (readSettings().updateChannel === channel) return;
- writeSettings({ updateChannel: channel });
+ // The model sets the channel it shows at launch: only a change is the user's choice.
+ if (channel === updateChannel()) return;
+ writeSettings({ updateChannel: channel, updateChannelChosen: true });
recordUpdateChannel(channel);
this.loaded = null;
this.schedule();
diff --git a/apps/cua-spaces-desktop/test/migrate-swift.test.ts b/apps/cua-spaces-desktop/test/migrate-swift.test.ts
index 60c404305d..eb396980e4 100644
--- a/apps/cua-spaces-desktop/test/migrate-swift.test.ts
+++ b/apps/cua-spaces-desktop/test/migrate-swift.test.ts
@@ -104,7 +104,7 @@ describe("migrateFromSwiftApp", () => {
expect(patch?.swiftMigration?.copied).toEqual(["onboarding.json"]);
});
- it("marks a Mac without the Swift app, and never turns updates on", () => {
+ it("marks a Mac without the Swift app, and writes no update choice", () => {
const m = machine();
const patch = migrateFromSwiftApp({ ...m, settings: {}, defaultsXml: null, primaryHeight: 1117, now });
expect(patch).toEqual({ swiftMigration: { at: "2026-10-07T12:00:00.000Z", found: false, copied: [] } });
diff --git a/apps/cua-spaces-desktop/test/update-prefs.test.ts b/apps/cua-spaces-desktop/test/update-prefs.test.ts
new file mode 100644
index 0000000000..ccaae49ee1
--- /dev/null
+++ b/apps/cua-spaces-desktop/test/update-prefs.test.ts
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+import { describe, expect, it } from "vitest";
+import type { Settings, SwiftMigration } from "../src/settings";
+import { autoCheckPref, autoInstallPref, channelPref, type UpdateChannel } from "../src/update-prefs";
+
+const moved = (m: Partial<SwiftMigration> = {}): Settings => ({
+ swiftMigration: { at: "2026-10-14T18:05:04.636Z", found: true, copied: ["settings.json"], ...m },
+});
+const fresh: Settings = { swiftMigration: { at: "2026-10-14T18:05:04.636Z", found: false, copied: [] } };
+// macOS before the Sparkle cutover: only Beta is served.
+const macServed = (c: UpdateChannel) => c === "beta";
+
+describe("autoCheckPref", () => {
+ it("keeps Sparkle's automatic checks on for someone who moved from the Swift app", () => {
+ // What a test Mac had after installing the Electron beta over Swift 0.8.0:
+ // Sparkle's checks were on by the Info.plist, so the defaults held no key.
+ expect(autoCheckPref(moved())).toBe(true);
+ expect(autoCheckPref(moved({ sparkleAutomaticChecks: true }))).toBe(true);
+ });
+
+ it("keeps them off when the user had turned them off in the Swift app", () => {
+ expect(autoCheckPref(moved({ sparkleAutomaticChecks: false }))).toBe(false);
+ });
+
+ it("follows the choice made in this app over Sparkle's", () => {
+ expect(autoCheckPref({ ...moved(), autoUpdate: false })).toBe(false);
+ expect(autoCheckPref({ ...moved({ sparkleAutomaticChecks: false }), autoUpdate: true })).toBe(true);
+ });
+
+ it("stays opt-in everywhere else", () => {
+ expect(autoCheckPref({})).toBe(false);
+ expect(autoCheckPref(fresh)).toBe(false);
+ expect(autoCheckPref({}, { CUA_SPACES_AUTO_UPDATE: "1" })).toBe(true);
+ expect(autoCheckPref({ autoUpdate: true })).toBe(true);
+ });
+});
+
+describe("autoInstallPref", () => {
+ it("follows Sparkle's automatic downloads, off by default", () => {
+ expect(autoInstallPref(moved())).toBe(false);
+ expect(autoInstallPref(moved({ sparkleAutomaticDownloads: true }))).toBe(true);
+ expect(autoInstallPref({ ...moved({ sparkleAutomaticDownloads: true }), autoInstall: false })).toBe(false);
+ expect(autoInstallPref(fresh)).toBe(false);
+ expect(autoInstallPref({ autoInstall: true })).toBe(true);
+ });
+});
+
+describe("channelPref", () => {
+ it("uses the build's channel when nothing is saved", () => {
+ expect(channelPref({}, "beta", macServed)).toBe("beta");
+ expect(channelPref({}, "stable", () => true)).toBe("stable");
+ });
+
+ it("drops a carried-over channel this app isn't served on", () => {
+ // Swift's "stable" on a macOS Electron beta: Stable has no Electron feed yet.
+ expect(channelPref({ ...moved(), updateChannel: "stable" }, "beta", macServed)).toBe("beta");
+ // After the cutover (Stable served), the Swift choice holds.
+ expect(channelPref({ ...moved(), updateChannel: "stable" }, "beta", () => true)).toBe("stable");
+ expect(channelPref({ ...moved(), updateChannel: "beta" }, "stable", macServed)).toBe("beta");
+ });
+
+ it("keeps a channel the user picked in this app", () => {
+ expect(channelPref({ updateChannel: "stable", updateChannelChosen: true }, "beta", macServed)).toBe("stable");
+ });
+});