From a14552a474bafa0c494fa1750828b7820772f753 Mon Sep 17 00:00:00 2001 From: Haze <709547807@qq.com> Date: Thu, 26 Feb 2026 17:08:21 +0800 Subject: [PATCH] fix(updater): opt macos electron updator (#187) --- electron/main/index.ts | 4 +--- electron/main/updater.ts | 43 +++++++++++++--------------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 3dd6b64a2..1470b4c13 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -231,9 +231,7 @@ app.on('window-all-closed', () => { app.on('before-quit', () => { isQuitting = true; // Fire-and-forget: do not await gatewayManager.stop() here. - // Awaiting inside a before-quit handler can stall Electron's - // replyToApplicationShouldTerminate: call when the quit is initiated - // by Squirrel.Mac (quitAndInstall), preventing the app from ever exiting. + // Awaiting inside before-quit can stall Electron's quit sequence. void gatewayManager.stop().catch((err) => { logger.warn('gatewayManager.stop() error during quit:', err); }); diff --git a/electron/main/updater.ts b/electron/main/updater.ts index 9c23f1ddf..42a523018 100644 --- a/electron/main/updater.ts +++ b/electron/main/updater.ts @@ -52,22 +52,14 @@ export class AppUpdater extends EventEmitter { constructor() { super(); - // Configure auto-updater autoUpdater.autoDownload = false; - // Must be true on macOS so that MacUpdater.updateDownloaded() triggers - // nativeUpdater.checkForUpdates() during the download phase, which lets - // Squirrel.Mac pre-stage the update. When false, the Squirrel download - // is deferred entirely to quitAndInstall() time, where it races against - // any safety timeout and often loses — resulting in the app quitting - // without installing the update. autoUpdater.autoInstallOnAppQuit = true; - // Use logger autoUpdater.logger = { - info: (msg: string) => console.log('[Updater]', msg), - warn: (msg: string) => console.warn('[Updater]', msg), - error: (msg: string) => console.error('[Updater]', msg), - debug: (msg: string) => console.debug('[Updater]', msg), + info: (msg: string) => logger.info('[Updater]', msg), + warn: (msg: string) => logger.warn('[Updater]', msg), + error: (msg: string) => logger.error('[Updater]', msg), + debug: (msg: string) => logger.debug('[Updater]', msg), }; // Override feed URL for prerelease channels so that @@ -76,7 +68,7 @@ export class AppUpdater extends EventEmitter { const channel = detectChannel(version); const feedUrl = `${OSS_BASE_URL}/${channel}`; - console.log(`[Updater] Version: ${version}, channel: ${channel}, feedUrl: ${feedUrl}`); + logger.info(`[Updater] Version: ${version}, channel: ${channel}, feedUrl: ${feedUrl}`); // Set channel so electron-updater requests the correct yml filename. // e.g. channel "alpha" → requests alpha-mac.yml, channel "latest" → requests latest-mac.yml @@ -148,7 +140,12 @@ export class AppUpdater extends EventEmitter { * Update status and notify renderer */ private updateStatus(newStatus: Partial): void { - this.status = { ...this.status, ...newStatus }; + this.status = { + status: newStatus.status ?? this.status.status, + info: newStatus.info, + progress: newStatus.progress, + error: newStatus.error, + }; this.sendToRenderer('update:status-changed', this.status); } @@ -191,7 +188,7 @@ export class AppUpdater extends EventEmitter { return result.updateInfo || null; } catch (error) { - console.error('[Updater] Check for updates failed:', error); + logger.error('[Updater] Check for updates failed:', error); this.updateStatus({ status: 'error', error: (error as Error).message || String(error) }); throw error; } @@ -204,22 +201,13 @@ export class AppUpdater extends EventEmitter { try { await autoUpdater.downloadUpdate(); } catch (error) { - console.error('[Updater] Download update failed:', error); + logger.error('[Updater] Download update failed:', error); throw error; } } - /** - * Install update and restart app - */ quitAndInstall(): void { - logger.info('[Updater] quitAndInstall called – invoking autoUpdater.quitAndInstall()'); - // On macOS, MacUpdater.quitAndInstall() either: - // (a) calls nativeUpdater.quitAndInstall() immediately (Squirrel already staged), or - // (b) waits for Squirrel to finish staging, then calls nativeUpdater.quitAndInstall(). - // In both cases electron-updater handles app.quit() internally. - // Do NOT add a safety timer that calls app.quit() — it kills the local - // proxy server that Squirrel.Mac is downloading from, aborting the update. + logger.info('[Updater] quitAndInstall called'); autoUpdater.quitAndInstall(); } @@ -243,9 +231,6 @@ export class AppUpdater extends EventEmitter { }, 1000); } - /** - * Cancel a running auto-install countdown. - */ cancelAutoInstall(): void { this.clearAutoInstallTimer(); this.sendToRenderer('update:auto-install-countdown', { seconds: -1, cancelled: true });