@devries-cameron20 / t3code-1 / commits / c1a7ce362b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): Check for Updates says when an update is available (#31957)

Julius Marminge committed Nov 14, 2026 at 18:45 UTC c1a7ce362b80b6f690a7a8c031cd37fe9947e5e7
2 files changed +138 -23
apps/desktop/src/window/DesktopApplicationMenu.test.ts
+106 -23
@@ -3,7 +3,9 @@ import { assert, describe, it } from "@effect/vitest";
3 import * as Deferred from "effect/Deferred";
4 import * as Effect from "effect/Effect";
5 import * as Layer from "effect/Layer";
6 +import * as Option from "effect/Option";
7
8 +import type { DesktopUpdateCheckResult, DesktopUpdateState } from "@t3tools/contracts";
9 import * as Electron from "electron";
10 import { vi } from "vite-plus/test";
11
@@ -18,6 +20,7 @@ import * as DesktopApplicationMenu from "./DesktopApplicationMenu.ts";
20 import * as DesktopConfig from "../app/DesktopConfig.ts";
21 import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
22 import * as DesktopUpdates from "../updates/DesktopUpdates.ts";
23 +import { createInitialDesktopUpdateState } from "../updates/updateMachine.ts";
24 import * as DesktopWindow from "./DesktopWindow.ts";
25
26 const environmentInput = {
@@ -56,27 +59,37 @@ const layerElectronApp = Layer.succeed(ElectronApp.ElectronApp, {
59 on: () => Effect.void,
60 } satisfies ElectronApp.ElectronApp["Service"]);
61
59 -const layerElectronDialog = Layer.succeed(ElectronDialog.ElectronDialog, {
60 - pickFolder: () => Effect.succeedNone,
61 - pickFiles: () => Effect.succeed([]),
62 - showMessageBox: () => Effect.succeed({ response: 0, checkboxChecked: false }),
63 - showErrorBox: () => Effect.void,
64 -} satisfies ElectronDialog.ElectronDialog["Service"]);
65 -
66 -const layerDesktopUpdates = Layer.succeed(DesktopUpdates.DesktopUpdates, {
67 - getState: Effect.die("unexpected getState"),
68 - isActionActive: Effect.succeed(false),
69 - isInstallActive: Effect.succeed(false),
70 - subscribe: Effect.die("unexpected subscribe"),
71 - emitState: Effect.void,
72 - disabledReason: Effect.succeedNone,
73 - configure: Effect.void,
74 - setChannel: () => Effect.die("unexpected setChannel"),
75 - check: () => Effect.die("unexpected check"),
76 - download: Effect.die("unexpected download"),
77 - install: Effect.die("unexpected install"),
78 - installPrepared: () => Effect.die("unexpected installPrepared"),
79 -} satisfies DesktopUpdates.DesktopUpdates["Service"]);
62 +interface MenuServices {
63 + readonly checkResult?: DesktopUpdateCheckResult;
64 + readonly shownMessageBox?: Deferred.Deferred<Electron.MessageBoxOptions>;
65 +}
66 +
67 +const layerElectronDialog = ({ shownMessageBox }: MenuServices) =>
68 + Layer.succeed(ElectronDialog.ElectronDialog, {
69 + pickFolder: () => Effect.succeedNone,
70 + pickFiles: () => Effect.succeed([]),
71 + showMessageBox: (options) =>
72 + (shownMessageBox ? Deferred.succeed(shownMessageBox, options) : Effect.void).pipe(
73 + Effect.as({ response: options.cancelId ?? 0, checkboxChecked: false }),
74 + ),
75 + showErrorBox: () => Effect.void,
76 + } satisfies ElectronDialog.ElectronDialog["Service"]);
77 +
78 +const layerDesktopUpdates = ({ checkResult }: MenuServices) =>
79 + Layer.succeed(DesktopUpdates.DesktopUpdates, {
80 + getState: Effect.die("unexpected getState"),
81 + isActionActive: Effect.succeed(false),
82 + isInstallActive: Effect.succeed(false),
83 + subscribe: Effect.die("unexpected subscribe"),
84 + emitState: Effect.void,
85 + disabledReason: Effect.succeedNone,
86 + configure: Effect.void,
87 + setChannel: () => Effect.die("unexpected setChannel"),
88 + check: () => (checkResult ? Effect.succeed(checkResult) : Effect.die("unexpected check")),
89 + download: Effect.die("unexpected download"),
90 + install: Effect.die("unexpected install"),
91 + installPrepared: () => Effect.die("unexpected installPrepared"),
92 + } satisfies DesktopUpdates.DesktopUpdates["Service"]);
93
94 const layerDesktopWindow = (selectedAction: Deferred.Deferred<string>) =>
95 Layer.succeed(DesktopWindow.DesktopWindow, {
@@ -113,6 +126,7 @@ const configureMenu = (
126 selectedAction: Deferred.Deferred<string>,
127 applicationMenuTemplate: Deferred.Deferred<readonly Electron.MenuItemConstructorOptions[]>,
128 environment: Partial<DesktopEnvironment.MakeDesktopEnvironmentInput> = {},
129 + services: MenuServices = {},
130 ) =>
131 Effect.gen(function* () {
132 const menu = yield* DesktopApplicationMenu.DesktopApplicationMenu;
@@ -122,8 +136,8 @@ const configureMenu = (
136 DesktopApplicationMenu.layer.pipe(
137 Layer.provideMerge(layerElectronMenu(applicationMenuTemplate)),
138 Layer.provideMerge(layerDesktopWindow(selectedAction)),
125 - Layer.provideMerge(layerDesktopUpdates),
126 - Layer.provideMerge(layerElectronDialog),
139 + Layer.provideMerge(layerDesktopUpdates(services)),
140 + Layer.provideMerge(layerElectronDialog(services)),
141 Layer.provideMerge(layerElectronApp),
142 Layer.provideMerge(
143 DesktopEnvironment.layer({ ...environmentInput, ...environment }).pipe(
@@ -134,6 +148,54 @@ const configureMenu = (
148 ),
149 );
150
151 +const checkForUpdatesFromMacMenu = (state: Partial<DesktopUpdateState>) =>
152 + Effect.gen(function* () {
153 + const applicationMenuTemplate =
154 + yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();
155 + const shownMessageBox = yield* Deferred.make<Electron.MessageBoxOptions>();
156 + yield* configureMenu(
157 + yield* Deferred.make<string>(),
158 + applicationMenuTemplate,
159 + { platform: "darwin" },
160 + {
161 + checkResult: {
162 + checked: true,
163 + state: {
164 + ...createInitialDesktopUpdateState(
165 + "0.1.5",
166 + { hostArch: "arm64", appArch: "arm64", runningUnderArm64Translation: false },
167 + "latest",
168 + ),
169 + enabled: true,
170 + ...state,
171 + },
172 + },
173 + shownMessageBox,
174 + },
175 + );
176 +
177 + const appMenu = (yield* Deferred.await(applicationMenuTemplate))[0];
178 + if (!Array.isArray(appMenu?.submenu)) {
179 + throw new Error("Expected the macOS app menu submenu to be an array.");
180 + }
181 + const checkForUpdates = appMenu.submenu.find((item) => item.label === "Check for Updates...");
182 + if (typeof checkForUpdates?.click !== "function") {
183 + throw new Error("Expected Check for Updates... menu item to have a click handler.");
184 + }
185 +
186 + // Every stub completes synchronously, so the menu action has finished when click returns.
187 + checkForUpdates.click(
188 + {} as Electron.MenuItem,
189 + {} as Electron.BrowserWindow,
190 + {} as KeyboardEvent,
191 + );
192 + const dialog = yield* Deferred.poll(shownMessageBox);
193 + if (Option.isNone(dialog)) {
194 + throw new Error("Check for Updates... finished without showing any dialog.");
195 + }
196 + return yield* dialog.value;
197 + });
198 +
199 describe("DesktopApplicationMenu", () => {
200 it.effect("leaves the accelerator to Chromium instead of injecting a paste", () =>
201 Effect.gen(function* () {
@@ -285,4 +347,25 @@ describe("DesktopApplicationMenu", () => {
347 assert.equal(yield* Deferred.await(selectedAction), "main-reload");
348 }),
349 );
350 + it.effect("tells the user which update the menu check found", () =>
351 + Effect.gen(function* () {
352 + const dialog = yield* checkForUpdatesFromMacMenu({
353 + status: "available",
354 + availableVersion: "0.1.7",
355 + });
356 + assert.include(`${dialog.title ?? ""} ${dialog.message} ${dialog.detail ?? ""}`, "0.1.7");
357 + }),
358 + );
359 +
360 + it.effect("tells the user a downloaded update is ready when the menu check runs", () =>
361 + Effect.gen(function* () {
362 + const dialog = yield* checkForUpdatesFromMacMenu({
363 + status: "downloaded",
364 + availableVersion: "0.1.7",
365 + downloadedVersion: "0.1.7",
366 + downloadPercent: 100,
367 + });
368 + assert.include(`${dialog.title ?? ""} ${dialog.message} ${dialog.detail ?? ""}`, "0.1.7");
369 + }),
370 + );
371 });
apps/desktop/src/window/DesktopApplicationMenu.ts
+32
@@ -64,6 +64,9 @@ const runMainContentsCommand = Effect.fn("desktop.menu.runMainContentsCommand")(
64 yield* desktopWindow.runMainContentsCommand(command);
65 });
66
67 +const describeUpdate = (version: string | null) =>
68 + version === null ? "A new version of T3 Code" : `T3 Code ${version}`;
69 +
70 const checkForUpdatesFromMenu = Effect.gen(function* () {
71 const updates = yield* DesktopUpdates.DesktopUpdates;
72 const electronDialog = yield* ElectronDialog.ElectronDialog;
@@ -77,6 +80,35 @@ const checkForUpdatesFromMenu = Effect.gen(function* () {
80 message: `T3 Code ${updateState.currentVersion} is currently the newest version available.`,
81 buttons: ["OK"],
82 });
83 + } else if (updateState.status === "available") {
84 + const { response } = yield* electronDialog.showMessageBox({
85 + type: "info",
86 + title: "Update available",
87 + message: `${describeUpdate(updateState.availableVersion)} is available.`,
88 + detail: `You're running T3 Code ${updateState.currentVersion}.`,
89 + buttons: ["Download", "Later"],
90 + defaultId: 0,
91 + cancelId: 1,
92 + });
93 + if (response === 0) yield* updates.download;
94 + } else if (updateState.status === "downloading") {
95 + yield* electronDialog.showMessageBox({
96 + type: "info",
97 + title: "Update downloading",
98 + message: `${describeUpdate(updateState.availableVersion)} is already downloading.`,
99 + buttons: ["OK"],
100 + });
101 + } else if (updateState.status === "downloaded") {
102 + const { response } = yield* electronDialog.showMessageBox({
103 + type: "info",
104 + title: "Update ready",
105 + message: `${describeUpdate(updateState.downloadedVersion ?? updateState.availableVersion)} is ready to install.`,
106 + detail: "T3 Code will restart to install it. Any running tasks will be interrupted.",
107 + buttons: ["Restart", "Later"],
108 + defaultId: 0,
109 + cancelId: 1,
110 + });
111 + if (response === 0) yield* updates.install;
112 } else if (updateState.status === "error") {
113 yield* electronDialog.showMessageBox({
114 type: "warning",