fix: 增强并明确关闭app的相关行为 (#938)

* 分离close和minimize按钮行为

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

@ -206,18 +206,24 @@ class Background {
this.window.on('close', e => {
log('window close event');
let closeOpt = this.store.get('settings.closeAppOption');
if (this.willQuitApp && (closeOpt === 'exit' || closeOpt === 'ask')) {
/* the user tried to quit the app */
if (isMac) {
if (this.willQuitApp) {
this.window = null;
app.quit();
} else if (!this.willQuitApp && isMac) {
} else {
e.preventDefault();
this.window.hide();
}
} else {
let closeOpt = this.store.get('settings.closeAppOption');
if (this.willQuitApp && (closeOpt === 'exit' || closeOpt === 'ask')) {
this.window = null;
app.quit();
} else {
/* the user only tried to close the window */
e.preventDefault();
this.window.minimize();
this.window.hide();
}
}
});
@ -229,15 +235,6 @@ class Background {
this.store.set('window', this.window.getBounds());
});
this.window.on('minimize', () => {
if (
!isMac &&
this.store.get('settings.closeAppOption') === 'minimizeToTray'
) {
this.window.hide();
}
});
this.window.webContents.on('new-window', function (e, url) {
e.preventDefault();
log('open url');

@ -37,22 +37,25 @@ export function initIpcMain(win, store) {
});
ipcMain.on('close', e => {
if (process.platform == 'darwin') {
if (process.platform === 'darwin') {
win.hide();
exitAsk(e);
return;
}
} else {
let closeOpt = store.get('settings.closeAppOption');
console.log(closeOpt);
if (closeOpt === 'exit') {
win = null;
//app.quit();
app.exit(); //exit()直接关闭客户端不会执行quit();
} else if (closeOpt === 'minimize' || closeOpt === 'minimizeToTray') {
} else if (closeOpt === 'minimize') {
e.preventDefault(); //阻止默认行为
win.minimize(); //调用 最小化实例方法
} else if (closeOpt === 'minimizeToTray') {
e.preventDefault();
win.hide();
} else {
exitAsk(e);
exitAskWithoutMac(e);
}
}
});
@ -175,4 +178,38 @@ export function initIpcMain(win, store) {
log(err);
});
};
const exitAskWithoutMac = e => {
e.preventDefault(); //阻止默认行为
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) {
e.preventDefault(); //阻止默认行为
win.hide(); //调用 最小化实例方法
} else if (result.response === 1) {
win = null;
//app.quit();
app.exit(); //exit()直接关闭客户端不会执行quit();
}
})
.catch(err => {
log(err);
});
};
}

@ -76,4 +76,11 @@ export function ipcRenderer(vueInstance) {
ipcRenderer.on('nextUp', () => {
self.$refs.player.goToNextTracksPage();
});
ipcRenderer.on('rememberCloseAppOption', (event, value) => {
store.commit('updateSettings', {
key: 'closeAppOption',
value,
});
});
}

@ -165,7 +165,6 @@ export default {
text: 'Close App...',
ask: 'Ask',
exit: 'Exit',
minimize: 'Minimize',
minimizeToTray: 'Minimize to tray',
},
},

@ -160,7 +160,6 @@ export default {
text: 'Close App...',
ask: 'Ask',
exit: 'Exit',
minimize: 'Minimize',
minimizeToTray: 'Küçült',
},
},

@ -166,7 +166,6 @@ export default {
text: '关闭主面板时...',
ask: '询问',
exit: '退出',
minimize: '最小化',
minimizeToTray: '最小化到托盘',
},
},

@ -163,7 +163,6 @@ export default {
text: '關閉主面板時...',
ask: '詢問',
exit: '退出',
minimize: '最小化',
minimizeToTray: '最小化到系統列',
},
},

@ -295,9 +295,6 @@
<option value="exit">
{{ $t('settings.closeAppOption.exit') }}
</option>
<option value="minimize">
{{ $t('settings.closeAppOption.minimize') }}
</option>
<option value="minimizeToTray">
{{ $t('settings.closeAppOption.minimizeToTray') }}
</option>

Loading…
Cancel
Save