optimize: 优化快捷键设置功能:添加日志

pull/361/head
王良 2024-09-21 00:00:18 +08:00
parent 36e805415f
commit 98ed2340e4
1 changed files with 23 additions and 13 deletions

View File

@ -281,24 +281,34 @@ function initApp () {
} }
// 全局监听快捷键,用于 显示/隐藏 窗口 // 全局监听快捷键,用于 显示/隐藏 窗口
app.whenReady().then(() => { app.whenReady().then(async () => {
globalShortcut.unregisterAll() globalShortcut.unregisterAll()
if (DevSidecar.api.config.get().app.showHideShortcut) { if (DevSidecar.api.config.get().app.showHideShortcut) {
globalShortcut.register(DevSidecar.api.config.get().app.showHideShortcut, () => { try {
if (winIsHidden || !win.isFocused()) { const registerSuccess = globalShortcut.register(DevSidecar.api.config.get().app.showHideShortcut, () => {
if (!win.isFocused()) { if (winIsHidden || !win.isFocused()) {
win.focus() if (!win.isFocused()) {
} win.focus()
if (winIsHidden) { }
showWin() if (winIsHidden) {
showWin()
}
} else {
// linux快捷键不关闭窗口
if (!isLinux()) {
hideWin()
}
} }
})
if (registerSuccess) {
log.info('注册快捷键成功:', DevSidecar.api.config.get().app.showHideShortcut)
} else { } else {
// linux快捷键不关闭窗口 log.error('注册快捷键失败:', DevSidecar.api.config.get().app.showHideShortcut)
if (!isLinux()) {
hideWin()
}
} }
}) } catch (e) {
log.error('注册快捷键异常:', DevSidecar.api.config.get().app.showHideShortcut, ', error:', e)
}
} }
}) })
} }