Skip to content

Commit f423a4d

Browse files
fix(desktop): a failed update-track save keeps offering the current track's updates (pingdotgg#34917)
1 parent b53cd67 commit f423a4d

2 files changed

Lines changed: 36 additions & 8 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,32 @@ describe("DesktopUpdates", () => {
932932
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
933933
});
934934

935+
it.effect("keeps the current track's offers when a track switch fails to save", () => {
936+
const harness = makeHarness({
937+
setUpdateChannelError: new DesktopAppSettings.DesktopSettingsWriteError({
938+
operation: "replace-settings-file",
939+
path: "desktop-settings.json",
940+
cause: new Error("rename failed"),
941+
}),
942+
});
943+
944+
return Effect.scoped(
945+
Effect.gen(function* () {
946+
const updates = yield* DesktopUpdates.DesktopUpdates;
947+
yield* updates.configure;
948+
const error = yield* updates
949+
.setChannel("nightly", { minimumVersion: "1.2.5-nightly.20261028.1" })
950+
.pipe(Effect.flip);
951+
assert.equal(error._tag, "DesktopUpdateChannelPersistenceError");
952+
assert.equal((yield* updates.getState).channel, "latest");
953+
954+
harness.emit("update-available", { version: "1.2.4" });
955+
yield* flushCallbacks;
956+
assert.equal((yield* updates.getState).availableVersion, "1.2.4");
957+
}),
958+
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
959+
});
960+
935961
it.effect("keeps a saved Stable track across a restart without offering an older release", () => {
936962
// A Nightly build whose switch to Stable did not finish before the app quit.
937963
const harness = makeHarness({ appVersion: "1.2.4-nightly.20261027.1", savedChannel: "latest" });

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,10 @@ export const make = Effect.gen(function* () {
12291229
}
12301230

12311231
return yield* Effect.gen(function* () {
1232-
yield* Ref.set(releaseFloorRef, Option.fromNullishOr(options?.minimumVersion));
1232+
const previousFloor = yield* Ref.getAndSet(
1233+
releaseFloorRef,
1234+
Option.fromNullishOr(options?.minimumVersion),
1235+
);
12331236
const state = yield* Ref.get(updateStateRef);
12341237
const retained = state.downloadedVersion ?? state.availableVersion;
12351238
// A build from another track re-checks, so retrying a track switch finds an older release.
@@ -1242,13 +1245,12 @@ export const make = Effect.gen(function* () {
12421245
return state;
12431246
}
12441247

1245-
yield* desktopSettings
1246-
.setUpdateChannel(nextChannel)
1247-
.pipe(
1248-
Effect.mapError(
1249-
(cause) => new DesktopUpdateChannelPersistenceError({ channel: nextChannel, cause }),
1250-
),
1251-
);
1248+
yield* desktopSettings.setUpdateChannel(nextChannel).pipe(
1249+
Effect.onError(() => Ref.set(releaseFloorRef, previousFloor)),
1250+
Effect.mapError(
1251+
(cause) => new DesktopUpdateChannelPersistenceError({ channel: nextChannel, cause }),
1252+
),
1253+
);
12521254

12531255
const disabledReason = yield* resolveDisabledReason;
12541256
yield* setState(yield* baseUpdateState(nextChannel, disabledReason));

0 commit comments

Comments
 (0)