fix(updater): opt macos electron updator (#187)
This commit is contained in:
@@ -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<UpdateStatus>): 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 });
|
||||
|
||||
Reference in New Issue
Block a user