fix: 修复Linux下,关闭主面板时... 询问选项无效的bug (#969)

* fix: Linux close app ask cant work

* Update background.js

* fix: bug
master
memorydream 3 years ago committed by GitHub
parent 704732a046
commit 9d18ad51f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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();

Loading…
Cancel
Save