From 68587e84ed789dbf4b434a4157921e58a5ed46d8 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Thu, 25 Mar 2021 14:15:04 +0000 Subject: [PATCH] Add user settings for warn before exit --- src/electron-main.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/electron-main.js b/src/electron-main.js index a6d778a..6c41120 100644 --- a/src/electron-main.js +++ b/src/electron-main.js @@ -340,6 +340,12 @@ ipcMain.on('ipcCall', async function(ev, payload) { launcher.disable(); } break; + case 'shouldWarnBeforeExit': + ret = store.get('warnBeforeExit', true); + break; + case 'setWarnBeforeExit': + store.set('warnBeforeExit', args[0]); + break; case 'getMinimizeToTrayEnabled': ret = tray.hasTray(); break; @@ -921,19 +927,21 @@ app.on('ready', async () => { mainWindow = global.mainWindow = null; }); mainWindow.on('close', async (e) => { - const shouldCancelCloseRequest = dialog.showMessageBoxSync(mainWindow, { - type: "question", - buttons: ["Cancel", "Close Element"], - message: "Are you sure you want to quit?", - defaultId: 1, - cancelId: 0, - checkboxLabel: "Do not show this again", - checkboxChecked: false, - }) === 0; + if (store.get('warnBeforeExit', true)) { + const shouldCancelCloseRequest = dialog.showMessageBoxSync(mainWindow, { + type: "question", + buttons: ["Cancel", "Close Element"], + message: "Are you sure you want to quit?", + defaultId: 1, + cancelId: 0, + checkboxLabel: "Do not show this again", + checkboxChecked: false, + }) === 0; - if (shouldCancelCloseRequest) { - e.preventDefault(); - return false; + if (shouldCancelCloseRequest) { + e.preventDefault(); + return false; + } } // If we are not quitting and have a tray icon then minimize to tray