Merge pull request #2749 from element-hq/midhun/fix/681

Fix `Ctrl+Q` not closing the app
This commit is contained in:
R Midhun Suresh
2025-12-11 18:15:12 +05:30
committed by GitHub

View File

@@ -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));
if (shouldWarnBeforeExit && exitShortcutPressed && global.mainWindow) {
// We only care about the exit shortcuts here
if (!exitShortcutPressed || !global.mainWindow) return;
// 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,11 +529,11 @@ app.on("ready", async () => {
defaultId: 1,
cancelId: 0,
}) === 0;
if (shouldCancelCloseRequest) {
event.preventDefault();
}
if (shouldCancelCloseRequest) return;
}
// Exit the app
app.exit();
});
global.mainWindow.on("closed", () => {