mirror of
https://github.com/CringeStudios/element-desktop.git
synced 2025-01-19 07:54:59 +01:00
Merge pull request #173 from vector-im/gsouquet-warn-before-exit
This commit is contained in:
commit
76eef82274
@ -27,7 +27,9 @@ const argv = require('minimist')(process.argv, {
|
|||||||
alias: {help: "h"},
|
alias: {help: "h"},
|
||||||
});
|
});
|
||||||
|
|
||||||
const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu, autoUpdater, protocol} = require('electron');
|
const {
|
||||||
|
app, ipcMain, powerSaveBlocker, BrowserWindow, Menu, autoUpdater, protocol, dialog, globalShortcut,
|
||||||
|
} = require('electron');
|
||||||
const AutoLaunch = require('auto-launch');
|
const AutoLaunch = require('auto-launch');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
@ -253,6 +255,22 @@ let eventIndex = null;
|
|||||||
let mainWindow = null;
|
let mainWindow = null;
|
||||||
global.appQuitting = false;
|
global.appQuitting = false;
|
||||||
|
|
||||||
|
const warnBeforeExit = (event) => {
|
||||||
|
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,
|
||||||
|
}) === 0;
|
||||||
|
|
||||||
|
if (shouldCancelCloseRequest) {
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const deleteContents = async (p) => {
|
const deleteContents = async (p) => {
|
||||||
for (const entry of await afs.readdir(p)) {
|
for (const entry of await afs.readdir(p)) {
|
||||||
@ -340,6 +358,12 @@ ipcMain.on('ipcCall', async function(ev, payload) {
|
|||||||
launcher.disable();
|
launcher.disable();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'shouldWarnBeforeExit':
|
||||||
|
ret = store.get('warnBeforeExit', true);
|
||||||
|
break;
|
||||||
|
case 'setWarnBeforeExit':
|
||||||
|
store.set('warnBeforeExit', args[0]);
|
||||||
|
break;
|
||||||
case 'getMinimizeToTrayEnabled':
|
case 'getMinimizeToTrayEnabled':
|
||||||
ret = tray.hasTray();
|
ret = tray.hasTray();
|
||||||
break;
|
break;
|
||||||
@ -917,10 +941,16 @@ app.on('ready', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
globalShortcut.register("CommandOrControl+Q", warnBeforeExit);
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
globalShortcut.register("Alt+F4", warnBeforeExit);
|
||||||
|
globalShortcut.register("AltGr+F4 ", warnBeforeExit);
|
||||||
|
}
|
||||||
|
|
||||||
mainWindow.on('closed', () => {
|
mainWindow.on('closed', () => {
|
||||||
mainWindow = global.mainWindow = null;
|
mainWindow = global.mainWindow = null;
|
||||||
});
|
});
|
||||||
mainWindow.on('close', (e) => {
|
mainWindow.on('close', async (e) => {
|
||||||
// If we are not quitting and have a tray icon then minimize to tray
|
// If we are not quitting and have a tray icon then minimize to tray
|
||||||
if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
|
if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
|
||||||
// On Mac, closing the window just hides it
|
// On Mac, closing the window just hides it
|
||||||
|
Loading…
Reference in New Issue
Block a user