Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix(desktop): Update now retries a failed download before opening download_url

ogsamrat1e480cbd3c8a
diff --git a/apps/app/src/app/lib/update-gate.ts b/apps/app/src/app/lib/update-gate.ts
index 613ec7c6..5e84a815 100644
--- a/apps/app/src/app/lib/update-gate.ts
+++ b/apps/app/src/app/lib/update-gate.ts
@@ -97,7 +97,8 @@ export type RequiredUpdateAction =
* What "Update now" does, from the shell's updater: `installMode`
* "manual-dmg" (a macOS build without a Developer ID signature, which
* Squirrel cannot swap) and an unsupported updater send the user to
- * `download_url`; a failed check or download does too.
+ * `download_url`. After a failed check or download "Update now" tries
+ * once more, and opens `download_url` if that fails too.
*/
export function requiredUpdateAction(input: {
supported: boolean;
@@ -111,7 +112,6 @@ export function requiredUpdateAction(input: {
case "checking":
case "downloading":
return "wait";
- case "error":
case "blocked":
case "installer-opened":
return "open-download";
diff --git a/apps/app/src/react-app/shell/update-gate.tsx b/apps/app/src/react-app/shell/update-gate.tsx
index 9b795c11..32b162ec 100644
--- a/apps/app/src/react-app/shell/update-gate.tsx
+++ b/apps/app/src/react-app/shell/update-gate.tsx
@@ -70,26 +70,31 @@ function useRequiredUpdate(gate: UpdateGateState) {
}
}, [gate.status, installMode, updater, updaterState]);
+ // After "Update now": install once the download is ready; where it cannot
+ // be (the check found nothing, the download failed, policy holds it back),
+ // open download_url instead.
const previousState = useRef(updaterState);
+ const installDownloadStarted = useRef(false);
useEffect(() => {
const previous = previousState.current;
previousState.current = updaterState;
if (!installRequested) return;
- // A check that ended without an update (the feed is behind the
- // required version): the download page is the way forward.
- if (previous === "checking" && (updaterState === "idle" || updaterState === null)) {
+ const finish = (next: () => void) => {
setInstallRequested(false);
- openDownload(gate.downloadUrl);
+ installDownloadStarted.current = false;
+ next();
+ };
+ if (!supported || installMode === "manual-dmg") return finish(() => openDownload(gate.downloadUrl));
+ if (updaterState === "ready") return finish(() => void updater.installUpdateAndRestart());
+ if (updaterState === "available" && !installDownloadStarted.current) {
+ installDownloadStarted.current = true;
+ void updater.downloadUpdate();
return;
}
- const action = requiredUpdateAction({ supported, installMode, updaterState });
- if (action === "install") {
- setInstallRequested(false);
- void updater.installUpdateAndRestart();
- } else if (action === "open-download") {
- setInstallRequested(false);
- openDownload(gate.downloadUrl);
- }
+ const failed = previous !== updaterState
+ && (updaterState === "error" || updaterState === "blocked" || updaterState === "installer-opened");
+ const nothingFound = previous === "checking" && (updaterState === "idle" || updaterState === null);
+ if (failed || nothingFound) finish(() => openDownload(gate.downloadUrl));
}, [gate.downloadUrl, installMode, installRequested, supported, updater, updaterState]);
const updateNow = useCallback(() => {
@@ -102,10 +107,15 @@ function useRequiredUpdate(gate: UpdateGateState) {
void updater.installUpdateAndRestart();
return;
}
+ installDownloadStarted.current = false;
setInstallRequested(true);
if (action === "download-then-install") {
- if (updaterState === "available") void updater.downloadUpdate();
- else void updater.checkForUpdates();
+ if (updaterState === "available") {
+ installDownloadStarted.current = true;
+ void updater.downloadUpdate();
+ } else {
+ void updater.checkForUpdates();
+ }
}
}, [gate.downloadUrl, installMode, supported, updater, updaterState]);
diff --git a/apps/app/tests/update-gate.test.tsx b/apps/app/tests/update-gate.test.tsx
index 084c642c..7be61cbd 100644
--- a/apps/app/tests/update-gate.test.tsx
+++ b/apps/app/tests/update-gate.test.tsx
@@ -102,10 +102,13 @@ describe("Update now", () => {
// Ad-hoc signed macOS builds: Squirrel cannot swap them.
expect(requiredUpdateAction({ supported: true, installMode: "manual-dmg", updaterState: "ready" })).toBe("open-download");
expect(requiredUpdateAction({ supported: false, installMode: null, updaterState: null })).toBe("open-download");
- expect(requiredUpdateAction({ supported: true, installMode: "in-place", updaterState: "error" })).toBe("open-download");
expect(requiredUpdateAction({ supported: true, installMode: "in-place", updaterState: "blocked" })).toBe("open-download");
});
+ test("tries the download again after a failed check or download", () => {
+ expect(requiredUpdateAction({ supported: true, installMode: "in-place", updaterState: "error" })).toBe("download-then-install");
+ });
+
test("the download starts in the background as soon as an update is required", () => {
const base = { supported: true, installMode: "in-place" as const };
expect(shouldStartBackgroundDownload({ ...base, gate: required, updaterState: null })).toBe(true);