Skip to content

Commit

Permalink
optimize: 快捷键设置功能:优化退出软件时注销快捷键
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Sep 21, 2024
1 parent 95ea782 commit d73d53c
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/gui/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ async function beforeQuit () {
return DevSidecar.api.shutdown()
}
async function quit () {
globalShortcut.unregisterAll()
log.info('注销所有快捷键成功')

if (tray) {
tray.displayBalloon({ title: '正在关闭', content: '关闭中,请稍候。。。' })
}
Expand All @@ -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, () => {
Expand Down Expand Up @@ -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) {
Expand All @@ -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('注销所有快捷键成功')
}
})

Expand Down

0 comments on commit d73d53c

Please sign in to comment.