Merge pull request #2749 from element-hq/midhun/fix/681
Fix `Ctrl+Q` not closing the app
This commit is contained in:
+13
-6
@@ -504,11 +504,18 @@ app.on("ready", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
global.mainWindow.webContents.on("before-input-event", (event: Event, input: Input): void => {
|
global.mainWindow.webContents.on("before-input-event", (event: Event, input: Input): void => {
|
||||||
const shouldWarnBeforeExit = store.get("warnBeforeExit", true);
|
|
||||||
const exitShortcutPressed =
|
const exitShortcutPressed =
|
||||||
input.type === "keyDown" && exitShortcuts.some((shortcutFn) => shortcutFn(input, process.platform));
|
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 =
|
const shouldCancelCloseRequest =
|
||||||
dialog.showMessageBoxSync(global.mainWindow, {
|
dialog.showMessageBoxSync(global.mainWindow, {
|
||||||
type: "question",
|
type: "question",
|
||||||
@@ -522,11 +529,11 @@ app.on("ready", async () => {
|
|||||||
defaultId: 1,
|
defaultId: 1,
|
||||||
cancelId: 0,
|
cancelId: 0,
|
||||||
}) === 0;
|
}) === 0;
|
||||||
|
if (shouldCancelCloseRequest) return;
|
||||||
if (shouldCancelCloseRequest) {
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit the app
|
||||||
|
app.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
global.mainWindow.on("closed", () => {
|
global.mainWindow.on("closed", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user