Add prompt to warn before quitting the application

This commit is contained in:
Germain Souquet 2021-03-25 12:46:10 +00:00
parent b309562244
commit c9c0ceb757

View file

@ -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