The best way to control Claude Code, Codex and more from any computer or phone
Harden desktop auto-update timer lifecycle
- track and clear startup + poll update timers through one cleanup path - prevent update checks from starting while the app is quitting - reset startup timer before scheduling to avoid duplicate checks
Julius Marminge committed
Mar 3, 2026 at 21:14 UTC
3cffdce1c157bce72fda86a62376810e7c399b71
1 file changed
+15
-6
apps/desktop/src/main.ts
+15
-6
@@ -203,6 +203,7 @@ function getDestructiveMenuIcon(): Electron.NativeImage | undefined {
203
}
204
}
205
let updatePollTimer: ReturnType<typeof setInterval> | null = null;
206
+let updateStartupTimer: ReturnType<typeof setTimeout> | null = null;
207
let updateCheckInFlight = false;
208
let updateDownloadInFlight = false;
209
let updaterConfigured = false;
@@ -538,9 +539,14 @@ function configureAppIdentity(): void {
539
}
540
541
function clearUpdatePollTimer(): void {
541
- if (!updatePollTimer) return;
542
- clearInterval(updatePollTimer);
543
- updatePollTimer = null;
542
+ if (updateStartupTimer) {
543
+ clearTimeout(updateStartupTimer);
544
+ updateStartupTimer = null;
545
+ }
546
+ if (updatePollTimer) {
547
+ clearInterval(updatePollTimer);
548
+ updatePollTimer = null;
549
+ }
550
}
551
552
function emitUpdateState(): void {
@@ -570,7 +576,7 @@ function shouldEnableAutoUpdates(): boolean {
576
}
577
578
async function checkForUpdates(reason: string): Promise<void> {
573
- if (!updaterConfigured || updateCheckInFlight) return;
579
+ if (isQuitting || !updaterConfigured || updateCheckInFlight) return;
580
if (
581
updateState.status === "downloading" ||
582
updateState.status === "downloaded" ||
@@ -739,10 +745,13 @@ function configureAutoUpdater(): void {
745
console.info(`[desktop-updater] Update downloaded: ${info.version}`);
746
});
747
742
- const startupTimer = setTimeout(() => {
748
+ clearUpdatePollTimer();
749
+
750
+ updateStartupTimer = setTimeout(() => {
751
+ updateStartupTimer = null;
752
void checkForUpdates("startup");
753
}, AUTO_UPDATE_STARTUP_DELAY_MS);
745
- startupTimer.unref();
754
+ updateStartupTimer.unref();
755
756
updatePollTimer = setInterval(() => {
757
void checkForUpdates("poll");