fix: fix shortcut registration and unregistration
This commit is contained in:
parent
d7f4e4584a
commit
5d01d12d2a
@ -40,14 +40,27 @@ export function registerZoomShortcut(mainWindow: BrowserWindow) {
|
|||||||
globalShortcut.unregister('CommandOrControl+0')
|
globalShortcut.unregister('CommandOrControl+0')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当窗口获得焦点时注册快捷键
|
// Add check for window destruction
|
||||||
mainWindow.on('focus', registerShortcuts)
|
if (mainWindow.isDestroyed()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 当窗口失去焦点时注销快捷键
|
// When window gains focus, register shortcuts
|
||||||
mainWindow.on('blur', unregisterShortcuts)
|
mainWindow.on('focus', () => {
|
||||||
|
if (!mainWindow.isDestroyed()) {
|
||||||
|
registerShortcuts()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 初始注册(如果窗口已经处于焦点状态)
|
// When window loses focus, unregister shortcuts
|
||||||
if (mainWindow.isFocused()) {
|
mainWindow.on('blur', () => {
|
||||||
|
if (!mainWindow.isDestroyed()) {
|
||||||
|
unregisterShortcuts()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Initial registration (if window is already focused)
|
||||||
|
if (!mainWindow.isDestroyed() && mainWindow.isFocused()) {
|
||||||
registerShortcuts()
|
registerShortcuts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user