This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
88 lines (74 loc) · 1.97 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const {dialog} = require('electron');
let confirmQuit = true;
let beforeQuitHandler;
const createBeforeQuitHandler = app => {
let quitConfirmed = false;
return event => {
if (confirmQuit && !quitConfirmed && app.getWindows().size) {
event.preventDefault();
dialog.showMessageBox({
type: 'question',
buttons: ['OK', 'Cancel'],
defaultId: 0,
title: 'Quit Hyper?',
message: 'Quit Hyper?',
detail: 'All sessions will be closed.'
}, index => {
if (index === 0) {
quitConfirmed = true;
app.quit();
}
});
}
};
};
exports.decorateConfig = config => {
if (typeof config.confirmQuit !== undefined) {
confirmQuit = Boolean(config.confirmQuit);
}
return config;
};
exports.onApp = app => {
switch (process.platform) {
case 'win32':
// Windows confirmations happen in the middleware
break;
default:
if (beforeQuitHandler) {
app.off('before-quit', beforeQuitHandler);
}
beforeQuitHandler = createBeforeQuitHandler(app);
app.on('before-quit', beforeQuitHandler);
break;
}
};
exports.middleware = _ => next => action => {
const {dialog, app} = require('electron').remote;
let confirmQuit = true;
if (typeof app.config.getConfig().confirmQuit !== undefined) {
confirmQuit = Boolean(app.config.getConfig().confirmQuit);
}
switch (process.platform) {
case 'win32':
if (confirmQuit && action.type === 'UI_WINDOW_CLOSE') {
dialog.showMessageBox({
type: 'question',
buttons: ['OK', 'Cancel'],
defaultId: 0,
title: 'Quit Hyper?',
message: 'Quit Hyper?',
detail: 'All sessions will be closed.'
}, index => {
if (index === 0) {
next(action);
}
});
return;
}
break;
default:
// No special middleware for non-windows operating systems
break;
}
next(action);
};