From ea47d05044cb99521e8796165d41c84ad03f8a4c Mon Sep 17 00:00:00 2001 From: yougotwill Date: Thu, 20 Feb 2025 02:37:40 +1100 Subject: [PATCH] feat: fixed auto update restart there is a known issue with electron updater quit and install --- ts/session/fetch_latest_release/index.ts | 2 +- ts/updater/updater.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ts/session/fetch_latest_release/index.ts b/ts/session/fetch_latest_release/index.ts index b3f30ba67..b5799af25 100644 --- a/ts/session/fetch_latest_release/index.ts +++ b/ts/session/fetch_latest_release/index.ts @@ -24,7 +24,7 @@ async function fetchReleaseFromFSAndUpdateMain(userEd25519SecretKey: Uint8Array) const diff = Date.now() - lastFetchedTimestamp; if (diff < skipIfLessThan) { window.log.info( - `[updater] fetched release from fs ${Math.floor(diff / DURATION.MINUTES)}minutes ago, skipping until that's at least ${Math.floor(skipIfLessThan / DURATION.MINUTES)}` + `[updater] fetched release from fs ${Math.floor(diff / DURATION.MINUTES)} minutes ago, skipping until that's at least ${Math.floor(skipIfLessThan / DURATION.MINUTES)}` ); return; } diff --git a/ts/updater/updater.ts b/ts/updater/updater.ts index 46452e8b5..62d18841e 100644 --- a/ts/updater/updater.ts +++ b/ts/updater/updater.ts @@ -32,16 +32,20 @@ let stopped = false; autoUpdater.on(DOWNLOAD_PROGRESS, eventDownloadProgress => { console.log( - `[updater] download progress: ${filesize(eventDownloadProgress.transferred, { base: 10 })}/${filesize(eventDownloadProgress.total, { base: 10 })}` + `[updater] downloading ${filesize(eventDownloadProgress.transferred, { base: 10 })}/${filesize(eventDownloadProgress.total, { base: 10 })}` ); }); autoUpdater.on(UPDATE_DOWNLOADED, () => { isUpdating = true; console.log('[updater] update downloaded'); - console.info('[updater] calling quitAndInstall...'); - autoUpdater.quitAndInstall(); - isUpdating = false; + // https://github.com/electron-userland/electron-builder/issues/6058#issuecomment-1130344017 + setTimeout(() => { + console.info('[updater] calling quitAndInstall...'); + autoUpdater.quitAndInstall(); + app.exit(); + isUpdating = false; + }, 1000); }); export async function start( @@ -206,7 +210,6 @@ async function checkForUpdates( logger.info('[updater] calling windowMarkShouldQuit...'); windowMarkShouldQuit(); - logger.info('[updater] UPDATE_DOWNLOADED event should be emitted soon...', UPDATE_DOWNLOADED); } finally { isUpdating = false; }