Fix/chore fix on macos (#169)
This commit is contained in:
@@ -205,6 +205,10 @@ app.whenReady().then(() => {
|
|||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
mainWindow = createWindow();
|
mainWindow = createWindow();
|
||||||
|
} else if (mainWindow && !mainWindow.isDestroyed()) {
|
||||||
|
// On macOS, clicking the dock icon should show the window if it's hidden
|
||||||
|
mainWindow.show();
|
||||||
|
mainWindow.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -215,9 +219,15 @@ app.on('window-all-closed', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('before-quit', async () => {
|
app.on('before-quit', () => {
|
||||||
isQuitting = true;
|
isQuitting = true;
|
||||||
await gatewayManager.stop();
|
// 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.
|
||||||
|
void gatewayManager.stop().catch((err) => {
|
||||||
|
logger.warn('gatewayManager.stop() error during quit:', err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Export for testing
|
// Export for testing
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
import { autoUpdater, UpdateInfo, ProgressInfo, UpdateDownloadedEvent } from 'electron-updater';
|
import { autoUpdater, UpdateInfo, ProgressInfo, UpdateDownloadedEvent } from 'electron-updater';
|
||||||
import { BrowserWindow, app, ipcMain } from 'electron';
|
import { BrowserWindow, app, ipcMain } from 'electron';
|
||||||
|
import { logger } from '../utils/logger';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
/** Base CDN URL (without trailing channel path) */
|
/** Base CDN URL (without trailing channel path) */
|
||||||
@@ -53,7 +54,11 @@ export class AppUpdater extends EventEmitter {
|
|||||||
|
|
||||||
// Configure auto-updater
|
// Configure auto-updater
|
||||||
autoUpdater.autoDownload = false;
|
autoUpdater.autoDownload = false;
|
||||||
autoUpdater.autoInstallOnAppQuit = true;
|
// Set to false so quitAndInstall() always goes through the explicit
|
||||||
|
// nativeUpdater.checkForUpdates() → nativeUpdater.quitAndInstall() path,
|
||||||
|
// avoiding a race condition where squirrelDownloadedUpdate is false at
|
||||||
|
// click time and the else-branch silently does nothing.
|
||||||
|
autoUpdater.autoInstallOnAppQuit = false;
|
||||||
|
|
||||||
// Use logger
|
// Use logger
|
||||||
autoUpdater.logger = {
|
autoUpdater.logger = {
|
||||||
@@ -206,7 +211,19 @@ export class AppUpdater extends EventEmitter {
|
|||||||
* Install update and restart app
|
* Install update and restart app
|
||||||
*/
|
*/
|
||||||
quitAndInstall(): void {
|
quitAndInstall(): void {
|
||||||
|
logger.info('[Updater] quitAndInstall called – invoking autoUpdater.quitAndInstall()');
|
||||||
autoUpdater.quitAndInstall();
|
autoUpdater.quitAndInstall();
|
||||||
|
|
||||||
|
// Safety fallback: if Squirrel.Mac's relaunchToInstallUpdate doesn't trigger
|
||||||
|
// app.quit() within 5 seconds (race condition or staging delay), force-quit
|
||||||
|
// so ShipIt can proceed with the installation. The update will be installed
|
||||||
|
// but the app won't auto-relaunch; the user will need to open it manually.
|
||||||
|
const safetyTimer = setTimeout(() => {
|
||||||
|
logger.warn('[Updater] quitAndInstall safety timer fired – forcing app.quit()');
|
||||||
|
app.quit();
|
||||||
|
}, 5000);
|
||||||
|
// Clear the timer if the normal before-quit path fires first
|
||||||
|
app.once('before-quit', () => clearTimeout(safetyTimer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user