GeezerVison is showing github.com — fix(desktop): refresh queued updates before install · pingdotgg/t3code@6413b0f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/updates/DesktopUpdates.test.ts +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -337,6 +337,41 @@ describe("DesktopUpdates", () => { | 337 | 337 | ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); | 338 | 338 | }); | 339 | 339 |
| | 340 | + it.effect("checks for newer releases after an update has been downloaded", () => { | | 341 | + const harness = makeHarness(); | | 342 | + | | 343 | + return Effect.scoped( | | 344 | + Effect.gen(function* () { | | 345 | + const updates = yield* DesktopUpdates.DesktopUpdates; | | 346 | + yield* updates.configure; | | 347 | + | | 348 | + harness.emit("update-downloaded", { version: "1.2.4" }); | | 349 | + yield* flushCallbacks; | | 350 | + | | 351 | + const result = yield* updates.check("poll"); | | 352 | + assert.isTrue(result.checked); | | 353 | + | | 354 | + harness.emit("update-available", { version: "1.2.4" }); | | 355 | + yield* flushCallbacks; | | 356 | + | | 357 | + const unchangedState = yield* updates.getState; | | 358 | + assert.equal(unchangedState.status, "downloaded"); | | 359 | + assert.equal(unchangedState.downloadedVersion, "1.2.4"); | | 360 | + | | 361 | + const nextResult = yield* updates.check("poll"); | | 362 | + assert.isTrue(nextResult.checked); | | 363 | + | | 364 | + harness.emit("update-available", { version: "1.2.5" }); | | 365 | + yield* flushCallbacks; | | 366 | + | | 367 | + const state = yield* updates.getState; | | 368 | + assert.equal(state.status, "available"); | | 369 | + assert.equal(state.availableVersion, "1.2.5"); | | 370 | + assert.isNull(state.downloadedVersion); | | 371 | + }), | | 372 | + ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer))); | | 373 | + }); | | 374 | + | 340 | 375 | it.effect("keeps raw updater event failures out of update state", () => { | 341 | 376 | const harness = makeHarness(); | 342 | 377 | const cause = new Error( | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/updates/DesktopUpdates.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -353,7 +353,7 @@ export const make = Effect.gen(function* () { | 353 | 353 | if (yield* Ref.get(updateCheckInFlightRef)) return false; | 354 | 354 |
| 355 | 355 | const state = yield* Ref.get(updateStateRef); | 356 | | - if (state.status === "downloading" || state.status === "downloaded") { | | 356 | + if (state.status === "downloading") { | 357 | 357 | yield* logUpdaterInfo("skipping update check while update is active", { | 358 | 358 | reason, | 359 | 359 | status: state.status, | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/updates/updateMachine.test.ts +48Lines changed: 48 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,6 +55,54 @@ describe("updateMachine", () => { | 55 | 55 | expect(state.canRetry).toBe(true); | 56 | 56 | }); | 57 | 57 |
| | 58 | + it("preserves an already-downloaded update while checking the feed", () => { | | 59 | + const downloadedState = { | | 60 | + ...createInitialDesktopUpdateState("1.0.0", runtimeInfo, "latest"), | | 61 | + enabled: true, | | 62 | + status: "downloaded" as const, | | 63 | + availableVersion: "1.1.0", | | 64 | + downloadedVersion: "1.1.0", | | 65 | + releaseNotes: [{ version: "1.1.0", items: ["fix: queued update"] }], | | 66 | + downloadPercent: 100, | | 67 | + }; | | 68 | + const checking = reduceDesktopUpdateStateOnCheckStart( | | 69 | + downloadedState, | | 70 | + "2026-03-04T00:00:00.000Z", | | 71 | + ); | | 72 | + const failed = reduceDesktopUpdateStateOnCheckFailure( | | 73 | + checking, | | 74 | + "network unavailable", | | 75 | + "2026-03-04T00:00:01.000Z", | | 76 | + ); | | 77 | + | | 78 | + expect(checking.status).toBe("checking"); | | 79 | + expect(checking.downloadedVersion).toBe("1.1.0"); | | 80 | + expect(checking.releaseNotes).toEqual(downloadedState.releaseNotes); | | 81 | + expect(failed.status).toBe("downloaded"); | | 82 | + expect(failed.downloadedVersion).toBe("1.1.0"); | | 83 | + expect(failed.releaseNotes).toEqual(downloadedState.releaseNotes); | | 84 | + expect(failed.message).toBeNull(); | | 85 | + }); | | 86 | + | | 87 | + it("keeps the installer when the feed still offers its version", () => { | | 88 | + const state = reduceDesktopUpdateStateOnUpdateAvailable( | | 89 | + { | | 90 | + ...createInitialDesktopUpdateState("1.0.0", runtimeInfo, "latest"), | | 91 | + enabled: true, | | 92 | + status: "downloaded", | | 93 | + availableVersion: "1.1.0", | | 94 | + downloadedVersion: "1.1.0", | | 95 | + downloadPercent: 100, | | 96 | + }, | | 97 | + "1.1.0", | | 98 | + "2026-03-04T00:00:00.000Z", | | 99 | + ); | | 100 | + | | 101 | + expect(state.status).toBe("downloaded"); | | 102 | + expect(state.downloadedVersion).toBe("1.1.0"); | | 103 | + expect(state.downloadPercent).toBe(100); | | 104 | + }); | | 105 | + | 58 | 106 | it("preserves available version on download failure for retry", () => { | 59 | 107 | const state = reduceDesktopUpdateStateOnDownloadFailure( | 60 | 108 | { | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/updates/updateMachine.ts +20-6Lines changed: 20 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,13 +43,14 @@ export function reduceDesktopUpdateStateOnCheckStart( | 43 | 43 | state: DesktopUpdateState, | 44 | 44 | checkedAt: string, | 45 | 45 | ): DesktopUpdateState { | | 46 | + const hasDownloadedUpdate = state.downloadedVersion !== null; | 46 | 47 | return { | 47 | 48 | ...state, | 48 | 49 | status: "checking", | 49 | 50 | checkedAt, | 50 | | - releaseNotes: [], | | 51 | + releaseNotes: hasDownloadedUpdate ? state.releaseNotes : [], | 51 | 52 | message: null, | 52 | | - downloadPercent: null, | | 53 | + downloadPercent: hasDownloadedUpdate ? 100 : null, | 53 | 54 | errorContext: null, | 54 | 55 | canRetry: false, | 55 | 56 | }; | @@ -60,6 +61,18 @@ export function reduceDesktopUpdateStateOnCheckFailure( | 60 | 61 | message: string, | 61 | 62 | checkedAt: string, | 62 | 63 | ): DesktopUpdateState { | | 64 | + if (state.downloadedVersion !== null) { | | 65 | + return { | | 66 | + ...state, | | 67 | + status: "downloaded", | | 68 | + message: null, | | 69 | + checkedAt, | | 70 | + downloadPercent: 100, | | 71 | + errorContext: null, | | 72 | + canRetry: true, | | 73 | + }; | | 74 | + } | | 75 | + | 63 | 76 | return { | 64 | 77 | ...state, | 65 | 78 | status: "error", | @@ -77,17 +90,18 @@ export function reduceDesktopUpdateStateOnUpdateAvailable( | 77 | 90 | checkedAt: string, | 78 | 91 | releaseNotes: ReadonlyArray<DesktopUpdateReleaseNote> = [], | 79 | 92 | ): DesktopUpdateState { | | 93 | + const isDownloadedVersion = state.downloadedVersion === version; | 80 | 94 | return { | 81 | 95 | ...state, | 82 | | - status: "available", | | 96 | + status: isDownloadedVersion ? "downloaded" : "available", | 83 | 97 | availableVersion: version, | 84 | | - downloadedVersion: null, | | 98 | + downloadedVersion: isDownloadedVersion ? version : null, | 85 | 99 | releaseNotes, | 86 | | - downloadPercent: null, | | 100 | + downloadPercent: isDownloadedVersion ? 100 : null, | 87 | 101 | checkedAt, | 88 | 102 | message: null, | 89 | 103 | errorContext: null, | 90 | | - canRetry: false, | | 104 | + canRetry: isDownloadedVersion, | 91 | 105 | }; | 92 | 106 | } | 93 | 107 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/desktopUpdate.logic.test.ts +15-4Lines changed: 15 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,14 +73,25 @@ describe("desktop update button state", () => { | 73 | 73 | expect(getDesktopUpdateButtonTooltip(state)).toContain("Click to retry"); | 74 | 74 | }); | 75 | 75 |
| 76 | | - it("prefers install when a downloaded version already exists", () => { | | 76 | + it("prefers a newly available release over a stale downloaded version", () => { | 77 | 77 | const state: DesktopUpdateState = { | 78 | 78 | ...baseState, | 79 | 79 | status: "available", | | 80 | + availableVersion: "1.2.0", | | 81 | + downloadedVersion: "1.1.0", | | 82 | + }; | | 83 | + expect(resolveDesktopUpdateButtonAction(state)).toBe("download"); | | 84 | + }); | | 85 | + | | 86 | + it("hides the install action while checking for a newer release", () => { | | 87 | + const state: DesktopUpdateState = { | | 88 | + ...baseState, | | 89 | + status: "checking", | 80 | 90 | availableVersion: "1.1.0", | 81 | 91 | downloadedVersion: "1.1.0", | | 92 | + downloadPercent: 100, | 82 | 93 | }; | 83 | | - expect(resolveDesktopUpdateButtonAction(state)).toBe("install"); | | 94 | + expect(resolveDesktopUpdateButtonAction(state)).toBe("none"); | 84 | 95 | }); | 85 | 96 |
| 86 | 97 | it("hides the button for non-actionable check errors", () => { | @@ -290,15 +301,15 @@ describe("canCheckForUpdate", () => { | 290 | 301 | ); | 291 | 302 | }); | 292 | 303 |
| 293 | | - it("returns false once an update has been downloaded", () => { | | 304 | + it("returns true once an update has been downloaded so newer releases can be found", () => { | 294 | 305 | expect( | 295 | 306 | canCheckForUpdate({ | 296 | 307 | ...baseState, | 297 | 308 | status: "downloaded", | 298 | 309 | availableVersion: "1.1.0", | 299 | 310 | downloadedVersion: "1.1.0", | 300 | 311 | }), | 301 | | - ).toBe(false); | | 312 | + ).toBe(true); | 302 | 313 | }); | 303 | 314 |
| 304 | 315 | it("returns true when idle", () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/desktopUpdate.logic.ts +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,10 @@ export function getDesktopUpdateReleaseUrl(version: string | null): string | nul | 24 | 24 | export function resolveDesktopUpdateButtonAction( | 25 | 25 | state: DesktopUpdateState, | 26 | 26 | ): DesktopUpdateButtonAction { | 27 | | - if (state.downloadedVersion) { | | 27 | + if ( | | 28 | + state.downloadedVersion && | | 29 | + (state.status === "downloaded" || state.errorContext === "install") | | 30 | + ) { | 28 | 31 | return "install"; | 29 | 32 | } | 30 | 33 | if (state.status === "available") { | @@ -125,9 +128,6 @@ export function shouldHighlightDesktopUpdateError(state: DesktopUpdateState | nu | 125 | 128 | export function canCheckForUpdate(state: DesktopUpdateState | null): boolean { | 126 | 129 | if (!state || !state.enabled) return false; | 127 | 130 | return ( | 128 | | - state.status !== "checking" && | 129 | | - state.status !== "downloading" && | 130 | | - state.status !== "downloaded" && | 131 | | - state.status !== "disabled" | | 131 | + state.status !== "checking" && state.status !== "downloading" && state.status !== "disabled" | 132 | 132 | ); | 133 | 133 | } |
|