From d73d53cfc86a80424774a576c162e7ee5ad9b817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Sun, 22 Sep 2024 03:26:25 +0800 Subject: [PATCH] =?UTF-8?q?optimize:=20=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD=EF=BC=9A=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=80=80=E5=87=BA=E8=BD=AF=E4=BB=B6=E6=97=B6=E6=B3=A8=E9=94=80?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/gui/src/background.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index 93f8088..69c5675 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -257,9 +257,6 @@ async function beforeQuit () { return DevSidecar.api.shutdown() } async function quit () { - globalShortcut.unregisterAll() - log.info('注销所有快捷键成功') - if (tray) { tray.displayBalloon({ title: '正在关闭', content: '关闭中,请稍候。。。' }) } @@ -277,9 +274,7 @@ function initApp () { // 全局监听快捷键,用于 显示/隐藏 窗口 app.whenReady().then(async () => { - globalShortcut.unregisterAll() const showHideShortcut = DevSidecar.api.config.get().app.showHideShortcut - log.info('先注销所有快捷键,再根据配置设置一个全局快捷键:', showHideShortcut) if (showHideShortcut && showHideShortcut !== '无' && showHideShortcut.length > 1) { try { const registerSuccess = globalShortcut.register(DevSidecar.api.config.get().app.showHideShortcut, () => { @@ -342,11 +337,12 @@ if (!isFirstInstance) { log.info('before-quit') if (process.platform === 'darwin') { quit() - } else { - globalShortcut.unregisterAll() - log.info('注销所有快捷键成功') } }) + app.on('will-quit', () => { + globalShortcut.unregisterAll(); + log.info('应用关闭,注销所有快捷键') + }); app.on('second-instance', (event, commandLine, workingDirectory) => { log.info('new app started, command:', commandLine) if (win) { @@ -362,9 +358,6 @@ if (!isFirstInstance) { // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { quit() - } else { - globalShortcut.unregisterAll() - log.info('注销所有快捷键成功') } })