From 9d18ad51f6182742e72ba1b5ed9efaacc1598dbf Mon Sep 17 00:00:00 2001 From: memorydream <34763046+memorydream@users.noreply.github.com> Date: Mon, 11 Oct 2021 10:19:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DLinux=E4=B8=8B?= =?UTF-8?q?=EF=BC=8C=E5=85=B3=E9=97=AD=E4=B8=BB=E9=9D=A2=E6=9D=BF=E6=97=B6?= =?UTF-8?q?...=20=E8=AF=A2=E9=97=AE=E9=80=89=E9=A1=B9=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84bug=20(#969)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Linux close app ask cant work * Update background.js * fix: bug --- src/background.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/background.js b/src/background.js index de03a10..5f2946d 100644 --- a/src/background.js +++ b/src/background.js @@ -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();