|
|
|
@ -26,6 +26,49 @@ const log = text => {
|
|
|
|
|
console.log(`${clc.blueBright('[background.js]')} ${text}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const closeOnLinux = (e, win, store) => {
|
|
|
|
|
let closeOpt = store.get('settings.closeAppOption');
|
|
|
|
|
if (closeOpt !== 'exit') {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (closeOpt === 'ask') {
|
|
|
|
|
dialog
|
|
|
|
|
.showMessageBox({
|
|
|
|
|
type: 'info',
|
|
|
|
|
title: 'Information',
|
|
|
|
|
cancelId: 2,
|
|
|
|
|
defaultId: 0,
|
|
|
|
|
message: '确定要关闭吗?',
|
|
|
|
|
buttons: ['最小化到托盘', '直接退出'],
|
|
|
|
|
checkboxLabel: '记住我的选择',
|
|
|
|
|
})
|
|
|
|
|
.then(result => {
|
|
|
|
|
if (result.checkboxChecked && result.response !== 2) {
|
|
|
|
|
win.webContents.send(
|
|
|
|
|
'rememberCloseAppOption',
|
|
|
|
|
result.response === 0 ? 'minimizeToTray' : 'exit'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.response === 0) {
|
|
|
|
|
win.hide(); //调用 最小化实例方法
|
|
|
|
|
} else if (result.response === 1) {
|
|
|
|
|
win = null;
|
|
|
|
|
app.exit(); //exit()直接关闭客户端,不会执行quit();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
log(err);
|
|
|
|
|
});
|
|
|
|
|
} else if (closeOpt === 'exit') {
|
|
|
|
|
win = null;
|
|
|
|
|
app.quit();
|
|
|
|
|
} else {
|
|
|
|
|
win.hide();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isWindows = process.platform === 'win32';
|
|
|
|
|
const isMac = process.platform === 'darwin';
|
|
|
|
|
const isLinux = process.platform === 'linux';
|
|
|
|
@ -207,7 +250,9 @@ class Background {
|
|
|
|
|
this.window.on('close', e => {
|
|
|
|
|
log('window close event');
|
|
|
|
|
|
|
|
|
|
if (isMac) {
|
|
|
|
|
if (isLinux) {
|
|
|
|
|
closeOnLinux(e, this.window, this.store);
|
|
|
|
|
} else if (isMac) {
|
|
|
|
|
if (this.willQuitApp) {
|
|
|
|
|
this.window = null;
|
|
|
|
|
app.quit();
|
|
|
|
|