The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 10:00 UTC
Harden desktop update flow and prevent duplicate update actions
- Skip redundant update checks while update is available/downloading/downloaded - Wait for backend shutdown before `quitAndInstall` and improve updater error/progress handling - Prevent sidebar update button clicks during download while preserving tooltip interactivity
Julius Marminge committed
Mar 3, 2026 at 20:26 UTC
392d63231cce39b2dcd56435ef24579a8b4f06c6
2 files changed
+83
-12
apps/desktop/src/main.ts
+77
-10
@@ -425,7 +425,9 @@ function dispatchMenuAction(action: string): void {
425
426
function handleCheckForUpdatesMenuClick(): void {
427
if (updateState.status === "downloaded") {
428
- installDownloadedUpdate();
428
+ console.info(
429
+ "[desktop-updater] Check for updates clicked while an update is already downloaded; skipping automatic install.",
430
+ );
431
return;
432
}
433
@@ -576,7 +578,11 @@ function shouldEnableAutoUpdates(): boolean {
578
579
async function checkForUpdates(reason: string): Promise<void> {
580
if (!updaterConfigured || updateCheckInFlight) return;
579
- if (updateState.status === "downloading" || updateState.status === "downloaded") {
581
+ if (
582
+ updateState.status === "downloading" ||
583
+ updateState.status === "downloaded" ||
584
+ updateState.status === "available"
585
+ ) {
586
console.info(
587
`[desktop-updater] Skipping update check (${reason}) while status=${updateState.status}.`,
588
);
@@ -639,8 +645,9 @@ function installDownloadedUpdate(): void {
645
646
isQuitting = true;
647
clearUpdatePollTimer();
642
- stopBackend();
643
- autoUpdater.quitAndInstall();
648
+ void stopBackendAndWaitForExit().finally(() => {
649
+ autoUpdater.quitAndInstall();
650
+ });
651
}
652
653
function configureAutoUpdater(): void {
@@ -674,6 +681,7 @@ function configureAutoUpdater(): void {
681
autoUpdater.autoDownload = false;
682
autoUpdater.autoInstallOnAppQuit = false;
683
autoUpdater.allowPrerelease = app.getVersion().includes("-");
684
+ let lastLoggedDownloadMilestone = -1;
685
686
autoUpdater.on("checking-for-update", () => {
687
console.info("[desktop-updater] Looking for updates...");
@@ -687,6 +695,7 @@ function configureAutoUpdater(): void {
695
checkedAt: new Date().toISOString(),
696
message: null,
697
});
698
+ lastLoggedDownloadMilestone = -1;
699
console.info(`[desktop-updater] Update available: ${info.version}`);
700
});
701
autoUpdater.on("update-not-available", () => {
@@ -698,14 +707,19 @@ function configureAutoUpdater(): void {
707
checkedAt: new Date().toISOString(),
708
message: null,
709
});
710
+ lastLoggedDownloadMilestone = -1;
711
console.info("[desktop-updater] No updates available.");
712
});
713
autoUpdater.on("error", (error) => {
704
- const message = error instanceof Error ? error.message : String(error);
705
- setUpdateState({
706
- status: "error",
707
- message,
708
- });
714
+ const message = formatErrorMessage(error);
715
+ if (!updateCheckInFlight && !updateDownloadInFlight) {
716
+ setUpdateState({
717
+ status: "error",
718
+ message,
719
+ checkedAt: new Date().toISOString(),
720
+ downloadPercent: null,
721
+ });
722
+ }
723
console.error(`[desktop-updater] Updater error: ${message}`);
724
});
725
autoUpdater.on("download-progress", (progress) => {
@@ -715,7 +729,9 @@ function configureAutoUpdater(): void {
729
downloadPercent: progress.percent,
730
message: null,
731
});
718
- if (percent % 10 === 0) {
732
+ const milestone = percent - (percent % 10);
733
+ if (milestone > lastLoggedDownloadMilestone) {
734
+ lastLoggedDownloadMilestone = milestone;
735
console.info(`[desktop-updater] Download progress: ${percent}%`);
736
}
737
});
@@ -842,6 +858,57 @@ function stopBackend(): void {
858
}
859
}
860
861
+async function stopBackendAndWaitForExit(timeoutMs = 5_000): Promise<void> {
862
+ if (restartTimer) {
863
+ clearTimeout(restartTimer);
864
+ restartTimer = null;
865
+ }
866
+
867
+ const child = backendProcess;
868
+ backendProcess = null;
869
+ if (!child) return;
870
+ const backendChild = child;
871
+ if (backendChild.exitCode !== null || backendChild.signalCode !== null) return;
872
+
873
+ await new Promise<void>((resolve) => {
874
+ let settled = false;
875
+ let forceKillTimer: ReturnType<typeof setTimeout> | null = null;
876
+ let exitTimeoutTimer: ReturnType<typeof setTimeout> | null = null;
877
+
878
+ function settle(): void {
879
+ if (settled) return;
880
+ settled = true;
881
+ backendChild.off("exit", onExit);
882
+ if (forceKillTimer) {
883
+ clearTimeout(forceKillTimer);
884
+ }
885
+ if (exitTimeoutTimer) {
886
+ clearTimeout(exitTimeoutTimer);
887
+ }
888
+ resolve();
889
+ }
890
+
891
+ function onExit(): void {
892
+ settle();
893
+ }
894
+
895
+ backendChild.once("exit", onExit);
896
+ backendChild.kill("SIGTERM");
897
+
898
+ forceKillTimer = setTimeout(() => {
899
+ if (backendChild.exitCode === null && backendChild.signalCode === null) {
900
+ backendChild.kill("SIGKILL");
901
+ }
902
+ }, 2_000);
903
+ forceKillTimer.unref();
904
+
905
+ exitTimeoutTimer = setTimeout(() => {
906
+ settle();
907
+ }, timeoutMs);
908
+ exitTimeoutTimer.unref();
909
+ });
910
+}
911
+
912
function registerIpcHandlers(): void {
913
ipcMain.removeHandler(PICK_FOLDER_CHANNEL);
914
ipcMain.handle(PICK_FOLDER_CHANNEL, async () => {
apps/web/src/components/Sidebar.tsx
+6
-2
@@ -859,6 +859,9 @@ export default function Sidebar() {
859
: "Update available";
860
861
const desktopUpdateButtonDisabled = desktopUpdateState?.status === "downloading";
862
+ const desktopUpdateButtonInteractivityClasses = desktopUpdateButtonDisabled
863
+ ? "cursor-not-allowed opacity-60"
864
+ : "hover:bg-accent hover:text-foreground";
865
const desktopUpdateButtonClasses =
866
desktopUpdateState?.status === "downloaded"
867
? "text-emerald-500"
@@ -869,6 +872,7 @@ export default function Sidebar() {
872
const handleDesktopUpdateButtonClick = useCallback(() => {
873
const bridge = window.desktopBridge;
874
if (!bridge || !desktopUpdateState) return;
875
+ if (desktopUpdateState.status === "downloading") return;
876
877
if (desktopUpdateState.status === "available") {
878
void bridge.downloadUpdate().catch((error) => {
@@ -931,8 +935,8 @@ export default function Sidebar() {
935
<button
936
type="button"
937
aria-label={desktopUpdateTooltip}
934
- disabled={desktopUpdateButtonDisabled}
935
- className={`inline-flex size-7 ml-auto mt-2 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-60 ${desktopUpdateButtonClasses}`}
938
+ aria-disabled={desktopUpdateButtonDisabled || undefined}
939
+ className={`inline-flex size-7 ml-auto mt-2 items-center justify-center rounded-md text-muted-foreground transition-colors ${desktopUpdateButtonInteractivityClasses} ${desktopUpdateButtonClasses}`}
940
onClick={handleDesktopUpdateButtonClick}
941
>
942
<RocketIcon className="size-3.5" />