The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): restart prompt returns after relaunching with a downloaded update (#18095)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Rakshith Bhat committed
Oct 20, 2026 at 10:57 UTC
d445fdba5d41023a02811735abcad4f9439f6b9e
5 files changed
+480
-14
apps/desktop/src/electron/ElectronUpdater.test.ts
+224
-2
@@ -1,9 +1,27 @@
1
+// @effect-diagnostics nodeBuiltinImport:off -- Build real electron-updater disk fixtures with its SHA-512 encoding.
2
+import * as NodeServices from "@effect/platform-node/NodeServices";
3
+import * as NodeCrypto from "node:crypto";
4
+import * as NodeEvents from "node:events";
5
+import * as NodeModule from "node:module";
6
+import * as NodePath from "node:path";
7
+import * as Deferred from "effect/Deferred";
8
+import * as FileSystem from "effect/FileSystem";
9
+import * as Option from "effect/Option";
10
+import { AppImageUpdater } from "electron-updater/out/AppImageUpdater.js";
11
+import { DebUpdater } from "electron-updater/out/DebUpdater.js";
12
+import { MacUpdater } from "electron-updater/out/MacUpdater.js";
13
+import { GenericProvider } from "electron-updater/out/providers/GenericProvider.js";
14
+import type { UpdateDownloadedEvent } from "electron-updater/out/types.js";
15
+import { NsisUpdater } from "electron-updater/out/NsisUpdater.js";
16
+import * as DesktopUpdates from "../updates/DesktopUpdates.ts";
17
+import { flushCallbacks, makeHarness } from "../updates/updatesTestHarness.ts";
18
import { assert, describe, it } from "@effect/vitest";
19
import * as Effect from "effect/Effect";
20
import type { VerifyUpdateCodeSignature } from "electron-updater";
21
import { beforeEach, vi } from "vite-plus/test";
22
6
-const { autoUpdaterMock } = vi.hoisted(() => ({
23
+const { autoUpdaterMock, updaterOverride } = vi.hoisted(() => ({
24
+ updaterOverride: { current: undefined as import("electron-updater").AppUpdater | undefined },
25
autoUpdaterMock: {
26
allowDowngrade: false,
27
allowPrerelease: false,
@@ -24,7 +42,9 @@ const { autoUpdaterMock } = vi.hoisted(() => ({
42
}));
43
44
vi.mock("electron-updater", () => ({
27
- autoUpdater: autoUpdaterMock,
45
+ get autoUpdater() {
46
+ return updaterOverride.current ?? autoUpdaterMock;
47
+ },
48
}));
49
50
import * as ElectronUpdater from "./ElectronUpdater.ts";
@@ -221,3 +241,205 @@ describe("ElectronUpdater", () => {
241
);
242
});
243
});
244
+
245
+describe("installed electron-updater cache recovery", () => {
246
+ it.effect.each([
247
+ {
248
+ name: "Intel Mac",
249
+ platform: "darwin",
250
+ Updater: MacUpdater,
251
+ selected: "x64.zip",
252
+ other: "arm64.zip",
253
+ rosetta: false,
254
+ },
255
+ {
256
+ name: "Apple Silicon running Intel",
257
+ platform: "darwin",
258
+ Updater: MacUpdater,
259
+ selected: "arm64.zip",
260
+ other: "x64.zip",
261
+ rosetta: true,
262
+ },
263
+ {
264
+ name: "Windows",
265
+ platform: "win32",
266
+ Updater: NsisUpdater,
267
+ selected: "x64.exe",
268
+ other: "arm64.exe",
269
+ rosetta: false,
270
+ },
271
+ {
272
+ name: "Debian",
273
+ platform: "linux",
274
+ Updater: DebUpdater,
275
+ selected: "x64.deb",
276
+ other: "x64.AppImage",
277
+ rosetta: false,
278
+ },
279
+ {
280
+ name: "AppImage",
281
+ platform: "linux",
282
+ Updater: AppImageUpdater,
283
+ selected: "x64.AppImage",
284
+ other: "x64.deb",
285
+ rosetta: false,
286
+ },
287
+ ] as const)("restores only the package selected by $name", (scenario) =>
288
+ Effect.scoped(
289
+ Effect.gen(function* () {
290
+ const fs = yield* FileSystem.FileSystem;
291
+ const directory = yield* fs.makeTempDirectoryScoped();
292
+ const cacheDirectory = NodePath.join(directory, "custom-updater-cache", "pending");
293
+ const configPath = NodePath.join(directory, "app-update.yml");
294
+ yield* fs.writeFileString(configPath, "updaterCacheDirName: custom-updater-cache\n");
295
+ yield* fs.makeDirectory(cacheDirectory, { recursive: true });
296
+
297
+ const require = NodeModule.createRequire(import.meta.url);
298
+ require("electron");
299
+ const electronModule = require.cache[require.resolve("electron")]!;
300
+ const childProcess = require("node:child_process") as typeof import("node:child_process");
301
+ const originalElectron = electronModule.exports;
302
+ const originalArch = Object.getOwnPropertyDescriptor(process, "arch")!;
303
+ yield* Effect.acquireRelease(
304
+ Effect.sync(() => {
305
+ // MacUpdater's native Squirrel bridge and host probes are OS boundaries.
306
+ electronModule.exports = { autoUpdater: new NodeEvents.EventEmitter() };
307
+ Object.defineProperty(process, "arch", { value: "x64", configurable: true });
308
+ return vi
309
+ .spyOn(childProcess, "execFileSync")
310
+ .mockReturnValue(scenario.rosetta ? "sysctl.proc_translated: 1" : "x86_64");
311
+ }),
312
+ (probe) =>
313
+ Effect.sync(() => {
314
+ probe.mockRestore();
315
+ Object.defineProperty(process, "arch", originalArch);
316
+ electronModule.exports = originalElectron;
317
+ updaterOverride.current = undefined;
318
+ }),
319
+ );
320
+
321
+ const extensions =
322
+ scenario.platform === "darwin"
323
+ ? ["arm64.dmg", "x64.dmg", "arm64.zip", "x64.zip"]
324
+ : scenario.platform === "win32"
325
+ ? ["arm64.exe", "x64.exe"]
326
+ : ["arm64.AppImage", "x64.AppImage", "arm64.deb", "x64.deb"];
327
+ const files = extensions.map((extension) => {
328
+ const url = `T3-Code-1.2.4-${extension}`;
329
+ return { url, sha512: NodeCrypto.createHash("sha512").update(url).digest("base64") };
330
+ });
331
+ const info = {
332
+ version: "1.2.4",
333
+ releaseDate: "2026-10-01T00:00:00Z",
334
+ files,
335
+ path: files[0]!.url,
336
+ sha512: files[0]!.sha512,
337
+ };
338
+ yield* Effect.acquireRelease(
339
+ Effect.sync(() =>
340
+ vi.spyOn(GenericProvider.prototype, "getLatestVersion").mockResolvedValue(info),
341
+ ),
342
+ (feed) => Effect.sync(() => feed.mockRestore()),
343
+ );
344
+
345
+ // A fresh instance for each launch forces disk validation rather than in-memory reuse.
346
+ yield* Effect.forEach([scenario.other, scenario.selected], (cachedExtension) =>
347
+ Effect.scoped(
348
+ Effect.gen(function* () {
349
+ const cached = files.find((file) => file.url.endsWith(`-${cachedExtension}`))!;
350
+ yield* fs.writeFileString(NodePath.join(cacheDirectory, cached.url), cached.url);
351
+ yield* fs.writeFileString(
352
+ NodePath.join(cacheDirectory, "update-info.json"),
353
+ JSON.stringify({
354
+ fileName: cached.url,
355
+ sha512: cached.sha512,
356
+ isAdminRightsRequired: false,
357
+ }),
358
+ );
359
+ const updater = new scenario.Updater(undefined, {
360
+ version: "1.2.3",
361
+ name: "T3 Code",
362
+ isPackaged: true,
363
+ appUpdateConfigPath: configPath,
364
+ userDataPath: directory,
365
+ baseCachePath: directory,
366
+ whenReady: () => Promise.resolve(),
367
+ relaunch: vi.fn(),
368
+ quit: vi.fn(),
369
+ onQuit: vi.fn(),
370
+ });
371
+ updater.logger = null;
372
+ const networkDownload = vi.fn(() =>
373
+ Promise.reject(new Error("unexpected network download")),
374
+ );
375
+ Object.assign(updater, { httpExecutor: { download: networkDownload } });
376
+ if (updater instanceof MacUpdater) {
377
+ // Keep real selection, executeDownload, and hash validation; stop at native handoff.
378
+ Object.assign(updater, {
379
+ updateDownloaded: async (_file: unknown, event: UpdateDownloadedEvent) => {
380
+ updater.emit("update-downloaded", event);
381
+ return [];
382
+ },
383
+ });
384
+ }
385
+ updaterOverride.current = updater;
386
+ assert.deepEqual(
387
+ yield* ElectronUpdater.make.pendingDownloadDirectory,
388
+ Option.some(cacheDirectory),
389
+ );
390
+
391
+ const inspected = Deferred.makeUnsafe<void>();
392
+ const downloadFinished = Deferred.makeUnsafe<void>();
393
+ const download = vi.spyOn(updater, "downloadUpdate");
394
+ const harness = makeHarness({
395
+ platform: scenario.platform,
396
+ runningUnderArm64Translation: scenario.rosetta,
397
+ env: scenario.selected.endsWith("AppImage")
398
+ ? { APPIMAGE: "/test/T3-Code.AppImage" }
399
+ : {},
400
+ updater: {
401
+ ...ElectronUpdater.make,
402
+ downloadUpdate: ElectronUpdater.make.downloadUpdate.pipe(
403
+ Effect.ensuring(Deferred.succeed(downloadFinished, undefined)),
404
+ ),
405
+ },
406
+ fileSystem: {
407
+ ...fs,
408
+ readFileString: (path, encoding) =>
409
+ path === "/missing/resources/package-type" && scenario.selected.endsWith("deb")
410
+ ? Effect.succeed("deb")
411
+ : fs.readFileString(path, encoding),
412
+ exists: (path) =>
413
+ fs.exists(path).pipe(Effect.tap(() => Deferred.succeed(inspected, undefined))),
414
+ },
415
+ });
416
+ yield* Effect.scoped(
417
+ Effect.gen(function* () {
418
+ const updates = yield* DesktopUpdates.DesktopUpdates;
419
+ yield* updates.configure;
420
+ // AppImage activation reads the host environment; the fixture is intentionally not installed.
421
+ vi.spyOn(updater, "isUpdaterActive").mockReturnValue(true);
422
+ assert.isTrue((yield* updates.check("startup")).checked);
423
+ yield* Deferred.await(inspected);
424
+ yield* flushCallbacks;
425
+
426
+ if (cachedExtension === scenario.other) {
427
+ assert.equal(download.mock.calls.length, 0);
428
+ assert.equal((yield* updates.getState).status, "available");
429
+ } else {
430
+ yield* Deferred.await(downloadFinished);
431
+ yield* flushCallbacks;
432
+ assert.equal(download.mock.calls.length, 1);
433
+ assert.equal((yield* updates.getState).status, "downloaded");
434
+ assert.equal((yield* updates.getState).downloadedVersion, "1.2.4");
435
+ }
436
+ assert.equal(networkDownload.mock.calls.length, 0);
437
+ }),
438
+ ).pipe(Effect.provide(harness.layer));
439
+ }),
440
+ ),
441
+ );
442
+ }),
443
+ ).pipe(Effect.provide(NodeServices.layer)),
444
+ );
445
+});
apps/desktop/src/electron/ElectronUpdater.ts
+13
@@ -1,6 +1,7 @@
1
import * as Context from "effect/Context";
2
import * as Effect from "effect/Effect";
3
import * as Layer from "effect/Layer";
4
+import * as Option from "effect/Option";
5
import * as Schema from "effect/Schema";
6
import * as Scope from "effect/Scope";
7
@@ -68,6 +69,7 @@ export class ElectronUpdater extends Context.Service<
69
readonly setAllowDowngrade: (value: boolean) => Effect.Effect<void>;
70
readonly setFullChangelog: (value: boolean) => Effect.Effect<void>;
71
readonly setDisableDifferentialDownload: (value: boolean) => Effect.Effect<void>;
72
+ readonly pendingDownloadDirectory: Effect.Effect<Option.Option<string>>;
73
readonly checkForUpdates: Effect.Effect<void, ElectronUpdaterCheckForUpdatesError>;
74
readonly downloadUpdate: Effect.Effect<void, ElectronUpdaterDownloadUpdateError>;
75
readonly quitAndInstall: (options: {
@@ -163,6 +165,17 @@ export const make = ElectronUpdater.of({
165
autoUpdater.disableDifferentialDownload = value;
166
return Effect.void;
167
}),
168
+ // Use the updater's helper so cache lookup follows the same configuration as downloads.
169
+ pendingDownloadDirectory: Effect.tryPromise(() =>
170
+ (
171
+ autoUpdater as unknown as {
172
+ getOrCreateDownloadHelper: () => Promise<{ readonly cacheDirForPendingUpdate: string }>;
173
+ }
174
+ ).getOrCreateDownloadHelper(),
175
+ ).pipe(
176
+ Effect.map((helper) => helper.cacheDirForPendingUpdate),
177
+ Effect.option,
178
+ ),
179
checkForUpdates: Effect.suspend(() => {
180
const channel = autoUpdater.channel;
181
return Effect.tryPromise({
apps/desktop/src/updates/DesktopUpdates.test.ts
+110
@@ -273,6 +273,116 @@ describe("DesktopUpdates", () => {
273
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
274
});
275
276
+ it.effect("reuses an update an earlier launch downloaded once its check finishes", () => {
277
+ const releaseCheck = Deferred.makeUnsafe<void>();
278
+ const harness = makeHarness({
279
+ cachedDownloadSha512: "sha-1.2.4",
280
+ // electron-updater reports update-available while the check is running.
281
+ checkForUpdates: Effect.sync(() =>
282
+ harness.emit("update-available", {
283
+ version: "1.2.4",
284
+ files: [{ url: "T3-Code-1.2.4.zip", sha512: "sha-1.2.4" }],
285
+ }),
286
+ ).pipe(Effect.andThen(Deferred.await(releaseCheck))),
287
+ downloadUpdate: Effect.sync(() => harness.emit("update-downloaded", { version: "1.2.4" })),
288
+ });
289
+
290
+ return Effect.scoped(
291
+ Effect.gen(function* () {
292
+ const updates = yield* DesktopUpdates.DesktopUpdates;
293
+ yield* updates.configure;
294
+
295
+ const check = yield* Effect.forkChild(updates.check("startup"));
296
+ yield* flushCallbacks;
297
+ assert.equal(harness.downloadCount(), 0);
298
+ assert.equal((yield* updates.getState).status, "available");
299
+
300
+ yield* Deferred.succeed(releaseCheck, undefined);
301
+ yield* Fiber.join(check);
302
+ yield* flushCallbacks;
303
+
304
+ assert.equal(harness.downloadCount(), 1);
305
+ const state = yield* updates.getState;
306
+ assert.equal(state.status, "downloaded");
307
+ assert.equal(state.downloadedVersion, "1.2.4");
308
+ }),
309
+ ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
310
+ });
311
+
312
+ it.effect.each([
313
+ { name: "a newer release", cachedDownloadSha512: "older-release" },
314
+ { name: "an interrupted download", cachedFileExists: false },
315
+ { name: "unfinished metadata", cachedDownloadInfo: "{" },
316
+ ])("keeps $name click-to-download", (cache) => {
317
+ const harness = makeHarness({ cachedDownloadSha512: "release-sha", ...cache });
318
+
319
+ return Effect.scoped(
320
+ Effect.gen(function* () {
321
+ const updates = yield* DesktopUpdates.DesktopUpdates;
322
+ yield* updates.configure;
323
+ harness.emit("update-available", {
324
+ version: "1.2.5",
325
+ files: [{ url: "T3-Code-1.2.5.zip", sha512: "release-sha" }],
326
+ });
327
+ yield* flushCallbacks;
328
+
329
+ assert.equal(harness.downloadCount(), 0);
330
+ assert.equal((yield* updates.getState).status, "available");
331
+ assert.isTrue((yield* updates.download).accepted);
332
+ assert.equal(harness.downloadCount(), 1);
333
+ }),
334
+ ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
335
+ });
336
+
337
+ it.effect.each(["quitting", "newer release", "no longer available"] as const)(
338
+ "abandons pending cache recovery after %s",
339
+ (change) => {
340
+ const releaseCheck = Deferred.makeUnsafe<void>();
341
+ const harness = makeHarness({
342
+ cachedDownloadSha512: "cached-release",
343
+ checkForUpdates: Effect.sync(() =>
344
+ harness.emit("update-available", {
345
+ version: "1.2.4",
346
+ files: [{ url: "T3-Code-1.2.4.zip", sha512: "cached-release" }],
347
+ }),
348
+ ).pipe(Effect.andThen(Deferred.await(releaseCheck))),
349
+ });
350
+
351
+ return Effect.scoped(
352
+ Effect.gen(function* () {
353
+ const updates = yield* DesktopUpdates.DesktopUpdates;
354
+ yield* updates.configure;
355
+ const check = yield* Effect.forkChild(updates.check("startup"));
356
+ yield* flushCallbacks;
357
+ assert.equal((yield* updates.getState).status, "available");
358
+ assert.equal(harness.downloadCount(), 0);
359
+
360
+ if (change === "quitting") {
361
+ const desktop = yield* DesktopState.DesktopState;
362
+ yield* Ref.set(desktop.quitting, true);
363
+ } else if (change === "newer release") {
364
+ harness.emit("update-available", {
365
+ version: "1.2.5",
366
+ files: [{ url: "T3-Code-1.2.5.zip", sha512: "new-release" }],
367
+ });
368
+ } else {
369
+ harness.emit("update-not-available");
370
+ }
371
+ yield* flushCallbacks;
372
+ yield* Deferred.succeed(releaseCheck, undefined);
373
+ yield* Fiber.join(check);
374
+ yield* flushCallbacks;
375
+
376
+ assert.equal(harness.downloadCount(), 0);
377
+ assert.equal(
378
+ (yield* updates.getState).status,
379
+ change === "no longer available" ? "up-to-date" : "available",
380
+ );
381
+ }),
382
+ ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
383
+ },
384
+ );
385
+
386
it.effect("preserves a queued installer when the feed has no update", () => {
387
const harness = makeHarness();
388
apps/desktop/src/updates/DesktopUpdates.ts
+87
@@ -68,8 +68,17 @@ const UpdateInfo = Schema.Struct({
68
// fail the decode and block the update state transition. The shape is
69
// validated defensively in normalizeDesktopUpdateReleaseNotes.
70
releaseNotes: Schema.optional(Schema.Unknown),
71
+ files: Schema.optional(Schema.Unknown),
72
});
73
74
+const ReleaseFile = Schema.Struct({ url: Schema.String, sha512: Schema.String });
75
+type ReleaseFile = typeof ReleaseFile.Type;
76
+const ReleaseFiles = Schema.Array(ReleaseFile);
77
+
78
+const CachedDownloadInfo = Schema.fromJsonString(
79
+ Schema.Struct({ fileName: Schema.String, sha512: Schema.String }),
80
+);
81
+
82
const DownloadProgressInfo = Schema.Struct({
83
percent: Schema.Number,
84
});
@@ -83,6 +92,8 @@ const encodeInstallRecord = Schema.encodeEffect(DesktopUpdateInstallRecord);
92
const decodeAppUpdateYmlConfig = Schema.decodeUnknownEffect(AppUpdateYmlConfig);
93
const decodeUpdateInfo = Schema.decodeUnknownEffect(UpdateInfo);
94
const decodeDownloadProgressInfo = Schema.decodeUnknownEffect(DownloadProgressInfo);
95
+const decodeReleaseFiles = Schema.decodeUnknownOption(ReleaseFiles);
96
+const decodeCachedDownloadInfo = Schema.decodeUnknownEffect(CachedDownloadInfo);
97
98
const currentIsoTimestamp = DateTime.now.pipe(Effect.map(DateTime.formatIso));
99
@@ -335,6 +346,32 @@ function isArm64HostRunningIntelBuild(runtimeInfo: DesktopRuntimeInfo): boolean
346
return runtimeInfo.hostArch === "arm64" && runtimeInfo.appArch === "x64";
347
}
348
349
+// Match electron-updater 6.8.9's MacUpdater.filterFilesForArch and Provider.findFile
350
+// for T3's package feeds. Matching any artifact can trigger a different download.
351
+function selectUpdateFile(
352
+ files: ReadonlyArray<ReleaseFile>,
353
+ platform: NodeJS.Platform,
354
+ isDebPackage: boolean,
355
+ runtimeInfo: DesktopRuntimeInfo,
356
+): ReleaseFile | undefined {
357
+ let candidates = files;
358
+ if (platform === "darwin") {
359
+ const isArm64File = (file: ReleaseFile) => file.url.includes("arm64");
360
+ const preferArm64 = runtimeInfo.hostArch === "arm64" && files.some(isArm64File);
361
+ candidates = files.filter((file) => isArm64File(file) === preferArm64);
362
+ }
363
+ const extension =
364
+ platform === "darwin"
365
+ ? ".zip"
366
+ : platform === "win32"
367
+ ? ".exe"
368
+ : isDebPackage
369
+ ? ".deb"
370
+ : ".appimage";
371
+ const packageFiles = candidates.filter((file) => file.url.toLowerCase().endsWith(extension));
372
+ return packageFiles.find((file) => file.url.includes(runtimeInfo.appArch)) ?? packageFiles[0];
373
+}
374
+
375
/** @public Service construction is part of the canonical Effect module API. */
376
export const make = Effect.gen(function* () {
377
const config = yield* DesktopConfig.DesktopConfig;
@@ -453,6 +490,15 @@ export const make = Effect.gen(function* () {
490
),
491
);
492
493
+ const awaitIdleUpdateAction = Effect.scoped(
494
+ Effect.gen(function* () {
495
+ const completions = yield* PubSub.subscribe(finishedUpdateActions);
496
+ while (Option.isSome(yield* activeUpdateAction)) {
497
+ yield* PubSub.take(completions);
498
+ }
499
+ }),
500
+ );
501
+
502
const applyAutoUpdaterChannel = Effect.fn("desktop.updates.applyAutoUpdaterChannel")(function* (
503
channel: DesktopUpdateChannel,
504
) {
@@ -853,6 +899,44 @@ export const make = Effect.gen(function* () {
899
);
900
}).pipe(Effect.withSpan("desktop.updates.startPollers"));
901
902
+ const cachedDownloadSha512 = Effect.gen(function* () {
903
+ const pendingDirectory = yield* electronUpdater.pendingDownloadDirectory;
904
+ if (Option.isNone(pendingDirectory)) return Option.none<string>();
905
+ const info = yield* fileSystem
906
+ .readFileString(environment.path.join(pendingDirectory.value, "update-info.json"))
907
+ .pipe(Effect.flatMap(decodeCachedDownloadInfo));
908
+ const fileExists = yield* fileSystem.exists(
909
+ environment.path.join(pendingDirectory.value, info.fileName),
910
+ );
911
+ return fileExists ? Option.some(info.sha512) : Option.none<string>();
912
+ }).pipe(Effect.orElseSucceed(() => Option.none<string>()));
913
+
914
+ // downloadUpdate validates the cached bytes and restores install readiness.
915
+ // Only resume the selected artifact; a cache miss would start a network download.
916
+ const resumeCachedDownload = Effect.fn("desktop.updates.resumeCachedDownload")(function* (
917
+ version: string,
918
+ files: unknown,
919
+ ) {
920
+ const releaseFiles = decodeReleaseFiles(files);
921
+ if (Option.isNone(releaseFiles)) return;
922
+ const updateFile = selectUpdateFile(
923
+ releaseFiles.value,
924
+ environment.platform,
925
+ isDebPackage,
926
+ environment.runtimeInfo,
927
+ );
928
+ if (!updateFile) return;
929
+ const cachedSha512 = yield* cachedDownloadSha512;
930
+ if (Option.isNone(cachedSha512) || updateFile.sha512 !== cachedSha512.value) return;
931
+
932
+ // update-available arrives while its check still holds the action reservation.
933
+ yield* awaitIdleUpdateAction;
934
+ if (yield* Ref.get(desktopState.quitting)) return;
935
+ const state = yield* Ref.get(updateStateRef);
936
+ if (state.status !== "available" || state.availableVersion !== version) return;
937
+ yield* downloadAvailableUpdate;
938
+ });
939
+
940
const handleUpdateAvailable = Effect.fn("desktop.updates.handleUpdateAvailable")(function* (
941
raw: unknown,
942
) {
@@ -892,6 +976,9 @@ export const make = Effect.gen(function* () {
976
releaseNoteGroups: releaseNotes.length,
977
omittedReleaseCount,
978
});
979
+ if (state.downloadedVersion !== info.version) {
980
+ yield* resumeCachedDownload(info.version, info.files);
981
+ }
982
}),
983
),
984
Effect.catchCause((cause) => {
apps/desktop/src/updates/updatesTestHarness.ts
+46
-12
@@ -26,6 +26,13 @@ export interface UpdatesHarnessOptions {
26
readonly setUpdateChannelError?: DesktopAppSettings.DesktopSettingsWriteError;
27
readonly setDisableDifferentialDownload?: Effect.Effect<void>;
28
readonly downloadUpdate?: Effect.Effect<void>;
29
+ /** sha512 of a download an earlier launch left in electron-updater's cache. */
30
+ readonly cachedDownloadSha512?: string;
31
+ readonly cachedDownloadInfo?: string;
32
+ readonly cachedFileExists?: boolean;
33
+ readonly updater?: ElectronUpdater.ElectronUpdater["Service"];
34
+ readonly fileSystem?: FileSystem.FileSystem;
35
+ readonly runningUnderArm64Translation?: boolean;
36
readonly quitAndInstall?: Effect.Effect<void, ElectronUpdater.ElectronUpdaterQuitAndInstallError>;
37
readonly stopBackend?: Effect.Effect<void>;
38
readonly startBackend?: Effect.Effect<void>;
@@ -37,6 +44,8 @@ export interface UpdatesHarnessOptions {
44
readonly installRecord?: string | undefined;
45
}
46
47
+const PENDING_DOWNLOAD_DIRECTORY = "/cache/t3code-updater/pending";
48
+
49
export function makeHarness(options: UpdatesHarnessOptions = {}) {
50
let checkCount = 0;
51
let quitAndInstallCount = 0;
@@ -65,7 +74,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
74
}
75
};
76
68
- const layerUpdater = Layer.succeed(ElectronUpdater.ElectronUpdater, {
77
+ const stubUpdater = {
78
setFeedURL: (options) =>
79
Effect.sync(() => {
80
feedUrls.push(options);
@@ -84,6 +93,11 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
93
fullChangelog = value;
94
}),
95
setDisableDifferentialDownload: () => options.setDisableDifferentialDownload ?? Effect.void,
96
+ pendingDownloadDirectory: Effect.succeed(
97
+ options.cachedDownloadSha512 === undefined
98
+ ? Option.none()
99
+ : Option.some(PENDING_DOWNLOAD_DIRECTORY),
100
+ ),
101
checkForUpdates: Effect.sync(() => {
102
checkCount += 1;
103
}).pipe(Effect.andThen(options.checkForUpdates ?? Effect.void)),
@@ -105,7 +119,11 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
119
removeListener(eventName, listener as unknown as (...args: readonly unknown[]) => void);
120
}),
121
).pipe(Effect.asVoid),
108
- } satisfies ElectronUpdater.ElectronUpdater["Service"]);
122
+ } satisfies ElectronUpdater.ElectronUpdater["Service"];
123
+ const layerUpdater = Layer.succeed(
124
+ ElectronUpdater.ElectronUpdater,
125
+ options.updater ?? stubUpdater,
126
+ );
127
128
const layerWindow = Layer.succeed(ElectronWindow.ElectronWindow, {
129
create: () => Effect.die("unexpected BrowserWindow creation"),
@@ -161,7 +179,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
179
appPath: "/repo",
180
isPackaged: true,
181
resourcesPath: "/missing/resources",
164
- runningUnderArm64Translation: false,
182
+ runningUnderArm64Translation: options.runningUnderArm64Translation ?? false,
183
}).pipe(
184
Layer.provide(
185
Layer.mergeAll(
@@ -218,7 +236,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
236
let previousInstallRecord = options.installRecord;
237
const isInstallRecord = (path: string) =>
238
path.endsWith(DesktopUpdates.DESKTOP_UPDATE_INSTALL_RECORD_FILE);
221
- const layerFileSystem = FileSystem.layerNoop({
239
+ const stubFileSystem = FileSystem.layerNoop({
240
readFileString: (path) => {
241
const installRecord = isInstallRecord(path)
242
? (installRecords.get(path) ?? previousInstallRecord)
@@ -226,15 +244,28 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
244
if (installRecord !== undefined) return Effect.succeed(installRecord);
245
return path === "/missing/resources/package-type" && options.packageType !== undefined
246
? Effect.succeed(options.packageType)
229
- : Effect.fail(
230
- PlatformError.systemError({
231
- module: "FileSystem",
232
- method: "readFileString",
233
- _tag: "NotFound",
234
- pathOrDescriptor: path,
235
- }),
236
- );
247
+ : path === `${PENDING_DOWNLOAD_DIRECTORY}/update-info.json` &&
248
+ options.cachedDownloadSha512 !== undefined
249
+ ? Effect.succeed(
250
+ options.cachedDownloadInfo ??
251
+ JSON.stringify({
252
+ fileName: "update.zip",
253
+ sha512: options.cachedDownloadSha512,
254
+ }),
255
+ )
256
+ : Effect.fail(
257
+ PlatformError.systemError({
258
+ module: "FileSystem",
259
+ method: "readFileString",
260
+ _tag: "NotFound",
261
+ pathOrDescriptor: path,
262
+ }),
263
+ );
264
},
265
+ exists: (path) =>
266
+ Effect.succeed(
267
+ options.cachedFileExists !== false && path === `${PENDING_DOWNLOAD_DIRECTORY}/update.zip`,
268
+ ),
269
makeDirectory: () => Effect.void,
270
writeFileString: (path, data) =>
271
Effect.sync(() => {
@@ -249,6 +280,9 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
280
}),
281
});
282
283
+ const layerFileSystem = options.fileSystem
284
+ ? Layer.succeed(FileSystem.FileSystem, options.fileSystem)
285
+ : stubFileSystem;
286
const layer = DesktopUpdates.layer.pipe(
287
Layer.provide(layerFileSystem),
288
Layer.provideMerge(layerUpdater),