Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,13 @@ if (gotSingleInstanceLock) {
app.on("before-quit", (event) => {
if (isShuttingDown) return;
isShuttingDown = true;
if (updateManager && updateManager.isQuittingForUpdate) {
// Quit must proceed for the installer to run, so no preventDefault;
// sidecar shutdown is best-effort (the reaper cleans up orphans on relaunch).
performSyncTeardown();
sidecarRegistry.shutdownAll().catch(() => {});
return;
}
event.preventDefault();
performSyncTeardown();
sidecarRegistry.shutdownAll().finally(() => app.exit(0));
Expand Down
29 changes: 20 additions & 9 deletions src/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class UpdateManager {
this.lastUpdateInfo = null;
this.isInstalling = false;
this.isDownloading = false;
this.isQuittingForUpdate = false;
this.handleBeforeQuitForUpdate = null;
this.eventListeners = [];
this.updateCheckInterval = null;
this.windowManager = null;
Expand Down Expand Up @@ -142,6 +144,17 @@ class UpdateManager {
autoUpdater.on(event, handler);
this.eventListeners.push({ event, handler });
});

// electron-updater and Squirrel.Mac emit this on Electron's native
// autoUpdater (before any windows close), not on the electron-updater instance.
this.handleBeforeQuitForUpdate = () => {
this.isQuittingForUpdate = true;
if (this.windowManager) {
this.windowManager.isQuitting = true;
this.windowManager.hotkeyManager.unregisterAll();
}
};
require("electron").autoUpdater.on("before-quit-for-update", this.handleBeforeQuitForUpdate);
}

notifyRenderers(channel, data) {
Expand Down Expand Up @@ -254,15 +267,6 @@ class UpdateManager {
this.isInstalling = true;
console.log("🔄 Installing update and restarting...");

const { app, BrowserWindow } = require("electron");

// Set windowManager.isQuitting before removing close listeners
app.emit("before-quit");
app.removeAllListeners("window-all-closed");
BrowserWindow.getAllWindows().forEach((win) => {
win.removeAllListeners("close");
});

const isSilent = process.platform === "win32";
autoUpdater.quitAndInstall(isSilent, true);

Expand Down Expand Up @@ -334,6 +338,13 @@ class UpdateManager {
autoUpdater.removeListener(event, handler);
});
this.eventListeners = [];
if (this.handleBeforeQuitForUpdate) {
require("electron").autoUpdater.removeListener(
"before-quit-for-update",
this.handleBeforeQuitForUpdate
);
this.handleBeforeQuitForUpdate = null;
}
}
}

Expand Down
Loading