From 88426b8ece471a6f3997959d8e054b65ac6fae7b Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Thu, 11 Dec 2025 16:11:50 +0530 Subject: [PATCH 1/3] Explicitly close app on key press --- src/electron-main.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/electron-main.ts b/src/electron-main.ts index 8ff217fe..8d89c4af 100644 --- a/src/electron-main.ts +++ b/src/electron-main.ts @@ -525,6 +525,8 @@ app.on("ready", async () => { if (shouldCancelCloseRequest) { event.preventDefault(); + } else { + app.exit(); } } }); From fd3f5cb9a099ab7d6845ff666f0d5865a1e29ca4 Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Thu, 11 Dec 2025 17:52:41 +0530 Subject: [PATCH 2/3] Always prevent default behaviour --- src/electron-main.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/electron-main.ts b/src/electron-main.ts index 8d89c4af..3af76206 100644 --- a/src/electron-main.ts +++ b/src/electron-main.ts @@ -504,11 +504,18 @@ app.on("ready", async () => { }); global.mainWindow.webContents.on("before-input-event", (event: Event, input: Input): void => { - const shouldWarnBeforeExit = store.get("warnBeforeExit", true); const exitShortcutPressed = - input.type === "keyDown" && exitShortcuts.some((shortcutFn) => shortcutFn(input, process.platform)); + input.type === "keyDown" && exitShortcuts.some((shortcutFn) => shortcutFn(input, process.platform)); + + // We only care about the exit shortcuts here + if (!exitShortcutPressed || !global.mainWindow) return; - if (shouldWarnBeforeExit && exitShortcutPressed && global.mainWindow) { + // Prevent the default behaviour + event.preventDefault(); + + // Let's ask the user if they really want to exit the app + const shouldWarnBeforeExit = store.get("warnBeforeExit", true); + if (shouldWarnBeforeExit) { const shouldCancelCloseRequest = dialog.showMessageBoxSync(global.mainWindow, { type: "question", @@ -522,13 +529,11 @@ app.on("ready", async () => { defaultId: 1, cancelId: 0, }) === 0; - - if (shouldCancelCloseRequest) { - event.preventDefault(); - } else { - app.exit(); - } + if (shouldCancelCloseRequest) return; } + + // Exit the app + app.exit(); }); global.mainWindow.on("closed", () => { From 12746b710730f0faf7fee5c89fb05c93ff8b843c Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Thu, 11 Dec 2025 17:57:18 +0530 Subject: [PATCH 3/3] Fix lint --- src/electron-main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/electron-main.ts b/src/electron-main.ts index 3af76206..9b4b9f90 100644 --- a/src/electron-main.ts +++ b/src/electron-main.ts @@ -505,8 +505,8 @@ app.on("ready", async () => { global.mainWindow.webContents.on("before-input-event", (event: Event, input: Input): void => { const exitShortcutPressed = - input.type === "keyDown" && exitShortcuts.some((shortcutFn) => shortcutFn(input, process.platform)); - + input.type === "keyDown" && exitShortcuts.some((shortcutFn) => shortcutFn(input, process.platform)); + // We only care about the exit shortcuts here if (!exitShortcutPressed || !global.mainWindow) return;