Skip to content

Commit 815ccda

Browse files
Merge pull request #2749 from element-hq/midhun/fix/681
Fix `Ctrl+Q` not closing the app
2 parents 95b9277 + 12746b7 commit 815ccda

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/electron-main.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,18 @@ app.on("ready", async () => {
504504
});
505505

506506
global.mainWindow.webContents.on("before-input-event", (event: Event, input: Input): void => {
507-
const shouldWarnBeforeExit = store.get("warnBeforeExit", true);
508507
const exitShortcutPressed =
509508
input.type === "keyDown" && exitShortcuts.some((shortcutFn) => shortcutFn(input, process.platform));
510509

511-
if (shouldWarnBeforeExit && exitShortcutPressed && global.mainWindow) {
510+
// We only care about the exit shortcuts here
511+
if (!exitShortcutPressed || !global.mainWindow) return;
512+
513+
// Prevent the default behaviour
514+
event.preventDefault();
515+
516+
// Let's ask the user if they really want to exit the app
517+
const shouldWarnBeforeExit = store.get("warnBeforeExit", true);
518+
if (shouldWarnBeforeExit) {
512519
const shouldCancelCloseRequest =
513520
dialog.showMessageBoxSync(global.mainWindow, {
514521
type: "question",
@@ -522,11 +529,11 @@ app.on("ready", async () => {
522529
defaultId: 1,
523530
cancelId: 0,
524531
}) === 0;
525-
526-
if (shouldCancelCloseRequest) {
527-
event.preventDefault();
528-
}
532+
if (shouldCancelCloseRequest) return;
529533
}
534+
535+
// Exit the app
536+
app.exit();
530537
});
531538

532539
global.mainWindow.on("closed", () => {

0 commit comments

Comments
 (0)