From c9c0ceb757748ebed7db2b18a5ab4efaf68edb77 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Thu, 25 Mar 2021 12:46:10 +0000 Subject: [PATCH] Add prompt to warn before quitting the application --- src/electron-main.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/electron-main.js b/src/electron-main.js index 8ef8d6e..a6d778a 100644 --- a/src/electron-main.js +++ b/src/electron-main.js @@ -27,7 +27,7 @@ const argv = require('minimist')(process.argv, { alias: {help: "h"}, }); -const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu, autoUpdater, protocol} = require('electron'); +const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu, autoUpdater, protocol, dialog} = require('electron'); const AutoLaunch = require('auto-launch'); const path = require('path'); @@ -920,7 +920,22 @@ app.on('ready', async () => { mainWindow.on('closed', () => { mainWindow = global.mainWindow = null; }); - mainWindow.on('close', (e) => { + 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 (shouldCancelCloseRequest) { + e.preventDefault(); + return false; + } + // If we are not quitting and have a tray icon then minimize to tray if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) { // On Mac, closing the window just hides it