From 605e8143e09229d1c825f33afa26d1f2c10d8459 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 3 Mar 2026 19:21:09 -0800 Subject: [PATCH] Prevent redundant checks during desktop update download - Skip desktop auto-update checks while an update is downloading or already downloaded - Subscribe to update-state events before initial fetch in sidebar to avoid stale state races --- apps/desktop/src/main.ts | 6 ++++++ apps/web/src/components/Sidebar.tsx | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index e89cecbe917084385aec9bc877b5992a4df34d4e..9b7770a617b477d65d13db4563baf94a776d52b6 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -576,6 +576,12 @@ function shouldEnableAutoUpdates(): boolean { async function checkForUpdates(reason: string): Promise { if (!updaterConfigured || updateCheckInFlight) return; + if (updateState.status === "downloading" || updateState.status === "downloaded") { + console.info( + `[desktop-updater] Skipping update check (${reason}) while status=${updateState.status}.`, + ); + return; + } updateCheckInFlight = true; setUpdateState({ status: "checking", diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 46f5ab3faa305edc7c17096ec4fc6f81d4de0452..b6d49e235e88184e995005d98f8263a34f347d2e 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -812,18 +812,21 @@ export default function Sidebar() { } let disposed = false; + let receivedSubscriptionUpdate = false; + const unsubscribe = bridge.onUpdateState((nextState) => { + if (disposed) return; + receivedSubscriptionUpdate = true; + setDesktopUpdateState(nextState); + }); + void bridge .getUpdateState() .then((nextState) => { - if (disposed) return; + if (disposed || receivedSubscriptionUpdate) return; setDesktopUpdateState(nextState); }) .catch(() => undefined); - const unsubscribe = bridge.onUpdateState((nextState) => { - setDesktopUpdateState(nextState); - }); - return () => { disposed = true; unsubscribe(); -- 2.54.0