mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 21:28:06 +00:00
fix: 修复Linux下,关闭主面板时... 询问选项无效的bug (#969)
* fix: Linux close app ask cant work * Update background.js * fix: bug
This commit is contained in:
parent
54b69a71ef
commit
22aa51a1e6
1 changed files with 46 additions and 1 deletions
|
|
@ -26,6 +26,49 @@ const log = text => {
|
||||||
console.log(`${clc.blueBright('[background.js]')} ${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 isWindows = process.platform === 'win32';
|
||||||
const isMac = process.platform === 'darwin';
|
const isMac = process.platform === 'darwin';
|
||||||
const isLinux = process.platform === 'linux';
|
const isLinux = process.platform === 'linux';
|
||||||
|
|
@ -207,7 +250,9 @@ class Background {
|
||||||
this.window.on('close', e => {
|
this.window.on('close', e => {
|
||||||
log('window close event');
|
log('window close event');
|
||||||
|
|
||||||
if (isMac) {
|
if (isLinux) {
|
||||||
|
closeOnLinux(e, this.window, this.store);
|
||||||
|
} else if (isMac) {
|
||||||
if (this.willQuitApp) {
|
if (this.willQuitApp) {
|
||||||
this.window = null;
|
this.window = null;
|
||||||
app.quit();
|
app.quit();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue