Always revalidate desktop updates before install

This commit is contained in:
Mohamed Boudra
2026-07-16 20:17:58 +02:00
parent 04c71c5890
commit 7d80fdfd12
8 changed files with 340 additions and 285 deletions
+24 -11
View File
@@ -46,18 +46,20 @@ export function createBeforeQuitHandler({
app,
closeTransportSessions,
stopDesktopManagedDaemonIfNeeded,
installAppUpdateOnQuit,
onStopError,
onUpdateError,
}: {
app: BeforeQuitApp;
closeTransportSessions: () => void;
stopDesktopManagedDaemonIfNeeded: () => Promise<boolean>;
installAppUpdateOnQuit: () => Promise<boolean>;
onStopError: (error: unknown) => void;
onUpdateError: (error: unknown) => void;
}): (event: BeforeQuitEvent) => void {
// We always preventDefault on first quit so we can run the async stop
// decision, then call app.exit(0) — which bypasses Electron's
// close → window-all-closed → will-quit chain. The window-all-closed
// listener is a darwin no-op (macOS convention) and would otherwise
// veto a re-fired app.quit().
// The first quit waits for daemon shutdown and update revalidation. A validated
// update re-fires app.quit(); otherwise app.exit(0) bypasses Electron's macOS
// window-all-closed handler, which would veto that second quit.
let quitting = false;
return (event) => {
@@ -66,12 +68,23 @@ export function createBeforeQuitHandler({
quitting = true;
event.preventDefault();
void stopDesktopManagedDaemonIfNeeded()
.catch((error) => {
void (async () => {
try {
await stopDesktopManagedDaemonIfNeeded();
} catch (error) {
onStopError(error);
})
.finally(() => {
app.exit(0);
});
}
try {
const installingUpdate = await installAppUpdateOnQuit();
if (installingUpdate) {
return;
}
} catch (error) {
onUpdateError(error);
}
app.exit(0);
})();
};
}