Skip to content

Commit 1d838c1

Browse files
committed
fix(desktop): a rejected off-track download no longer stops background checks
1 parent 6571676 commit 1d838c1

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎apps/desktop/src/updates/DesktopUpdates.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,21 +715,29 @@ describe("DesktopUpdates", () => {
715715
});
716716

717717
it.effect("ignores a finished download from a track it no longer follows", () => {
718-
const harness = makeHarness({ platform: "win32" });
718+
const releaseDownload = Deferred.makeUnsafe<void>();
719+
const harness = makeHarness({
720+
platform: "win32",
721+
downloadUpdate: Deferred.await(releaseDownload),
722+
});
719723

720724
return Effect.scoped(
721725
Effect.gen(function* () {
722726
const updates = yield* DesktopUpdates.DesktopUpdates;
723727
yield* updates.configure;
724728
harness.emit("update-available", { version: "1.2.4" });
725729
yield* flushCallbacks;
726-
yield* updates.download;
730+
const download = yield* Effect.forkChild(updates.download, { startImmediately: true });
731+
yield* flushCallbacks;
727732
assert.equal(harness.autoInstallOnAppQuitCalls.at(-1), true);
728733
// A backed-out switch's download keeps reporting progress until it finishes.
729734
harness.emit("download-progress", { percent: 40 });
730735
yield* flushCallbacks;
736+
// electron-updater emits update-downloaded before downloadUpdate resolves.
731737
harness.emit("update-downloaded", { version: "1.2.4-nightly.20261027.1" });
732738
yield* flushCallbacks;
739+
yield* Deferred.succeed(releaseDownload, undefined);
740+
yield* Fiber.join(download);
733741

734742
const state = yield* updates.getState;
735743
assert.equal(state.downloadedVersion, null);

‎apps/desktop/src/updates/DesktopUpdates.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ export const make = Effect.gen(function* () {
390390
const failedDownloads = new Set<string>();
391391
// Manual checks can clear downloadedVersion while the native installer stays queued.
392392
let downloadedInstallerVersion: string | null = null;
393+
// electron-updater emits update-downloaded before downloadUpdate resolves.
394+
let downloadEventSeen = false;
393395
const notAppliedVersionRef = yield* Ref.make(Option.none<string>());
394396
// The release a track switch's database check cleared. A build crosses to another track only
395397
// through such a switch, and never below that release: version order alone cannot tell whether
@@ -630,8 +632,10 @@ export const make = Effect.gen(function* () {
630632
environment.platform !== "darwin" && !isDebPackage,
631633
);
632634
downloadedInstallerVersion = null;
635+
downloadEventSeen = false;
633636
yield* electronUpdater.downloadUpdate;
634-
downloadedInstallerVersion ??= state.availableVersion;
637+
// The event handler may have rejected an off-track download; keep its decision.
638+
if (!downloadEventSeen) downloadedInstallerVersion ??= state.availableVersion;
635639
if (downloadedInstallerVersion !== null) failedDownloads.delete(downloadedInstallerVersion);
636640
return { accepted: true, completed: true };
637641
}).pipe(
@@ -1118,6 +1122,7 @@ export const make = Effect.gen(function* () {
11181122
yield* decodeUpdateInfo(raw).pipe(
11191123
Effect.flatMap(
11201124
Effect.fn("desktop.updates.applyUpdateDownloaded")(function* (info) {
1125+
downloadEventSeen = true;
11211126
const state = yield* Ref.get(updateStateRef);
11221127
// A download can finish after its track switch moved on; never offer that build.
11231128
if (!(yield* offerable(info.version, state))) {

0 commit comments

Comments
 (0)