From de818282c811c5564dc16f0258b96183dbcaf47b Mon Sep 17 00:00:00 2001
From: memorydream <34763046+memorydream@users.noreply.github.com>
Date: Tue, 28 Sep 2021 19:05:34 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA=E5=B9=B6=E6=98=8E?=
=?UTF-8?q?=E7=A1=AE=E5=85=B3=E9=97=ADapp=E7=9A=84=E7=9B=B8=E5=85=B3?=
=?UTF-8?q?=E8=A1=8C=E4=B8=BA=20(#938)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 分离close和minimize按钮行为
* bug fix
---
src/background.js | 37 ++++++++++------------
src/electron/ipcMain.js | 63 +++++++++++++++++++++++++++++--------
src/electron/ipcRenderer.js | 7 +++++
src/locale/lang/en.js | 1 -
src/locale/lang/tr.js | 1 -
src/locale/lang/zh-CN.js | 1 -
src/locale/lang/zh-TW.js | 1 -
src/views/settings.vue | 3 --
8 files changed, 74 insertions(+), 40 deletions(-)
diff --git a/src/background.js b/src/background.js
index b3c90cb..de03a10 100644
--- a/src/background.js
+++ b/src/background.js
@@ -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 */
- this.window = null;
- app.quit();
- } else if (!this.willQuitApp && isMac) {
- e.preventDefault();
- this.window.hide();
+
+ if (isMac) {
+ if (this.willQuitApp) {
+ this.window = null;
+ app.quit();
+ } else {
+ e.preventDefault();
+ this.window.hide();
+ }
} else {
- /* the user only tried to close the window */
- e.preventDefault();
- this.window.minimize();
+ let closeOpt = this.store.get('settings.closeAppOption');
+ if (this.willQuitApp && (closeOpt === 'exit' || closeOpt === 'ask')) {
+ this.window = null;
+ app.quit();
+ } else {
+ e.preventDefault();
+ 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');
diff --git a/src/electron/ipcMain.js b/src/electron/ipcMain.js
index 2a89a95..f053775 100644
--- a/src/electron/ipcMain.js
+++ b/src/electron/ipcMain.js
@@ -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;
- }
-
- let closeOpt = store.get('settings.closeAppOption');
- if (closeOpt === 'exit') {
- win = null;
- //app.quit();
- app.exit(); //exit()直接关闭客户端,不会执行quit();
- } else if (closeOpt === 'minimize' || closeOpt === 'minimizeToTray') {
- e.preventDefault(); //阻止默认行为
- win.minimize(); //调用 最小化实例方法
} else {
- exitAsk(e);
+ let closeOpt = store.get('settings.closeAppOption');
+ console.log(closeOpt);
+ if (closeOpt === 'exit') {
+ win = null;
+ //app.quit();
+ app.exit(); //exit()直接关闭客户端,不会执行quit();
+ } else if (closeOpt === 'minimize') {
+ e.preventDefault(); //阻止默认行为
+ win.minimize(); //调用 最小化实例方法
+ } else if (closeOpt === 'minimizeToTray') {
+ e.preventDefault();
+ win.hide();
+ } else {
+ 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);
+ });
+ };
}
diff --git a/src/electron/ipcRenderer.js b/src/electron/ipcRenderer.js
index da3ccb5..0222658 100644
--- a/src/electron/ipcRenderer.js
+++ b/src/electron/ipcRenderer.js
@@ -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,
+ });
+ });
}
diff --git a/src/locale/lang/en.js b/src/locale/lang/en.js
index f7e55d2..a97b675 100644
--- a/src/locale/lang/en.js
+++ b/src/locale/lang/en.js
@@ -165,7 +165,6 @@ export default {
text: 'Close App...',
ask: 'Ask',
exit: 'Exit',
- minimize: 'Minimize',
minimizeToTray: 'Minimize to tray',
},
},
diff --git a/src/locale/lang/tr.js b/src/locale/lang/tr.js
index a774b11..f9432bc 100644
--- a/src/locale/lang/tr.js
+++ b/src/locale/lang/tr.js
@@ -160,7 +160,6 @@ export default {
text: 'Close App...',
ask: 'Ask',
exit: 'Exit',
- minimize: 'Minimize',
minimizeToTray: 'Küçült',
},
},
diff --git a/src/locale/lang/zh-CN.js b/src/locale/lang/zh-CN.js
index 2dfaaac..dfcac60 100644
--- a/src/locale/lang/zh-CN.js
+++ b/src/locale/lang/zh-CN.js
@@ -166,7 +166,6 @@ export default {
text: '关闭主面板时...',
ask: '询问',
exit: '退出',
- minimize: '最小化',
minimizeToTray: '最小化到托盘',
},
},
diff --git a/src/locale/lang/zh-TW.js b/src/locale/lang/zh-TW.js
index f506bf7..d195b54 100644
--- a/src/locale/lang/zh-TW.js
+++ b/src/locale/lang/zh-TW.js
@@ -163,7 +163,6 @@ export default {
text: '關閉主面板時...',
ask: '詢問',
exit: '退出',
- minimize: '最小化',
minimizeToTray: '最小化到系統列',
},
},
diff --git a/src/views/settings.vue b/src/views/settings.vue
index eaf6a0b..6f484f5 100644
--- a/src/views/settings.vue
+++ b/src/views/settings.vue
@@ -295,9 +295,6 @@
-