fix: register shortcut key error
This commit is contained in:
parent
2757535cf0
commit
7d2df1a8c5
@ -62,6 +62,7 @@ export function registerShortcuts(window: BrowserWindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handler = getShortcutHandler(shortcut)
|
const handler = getShortcutHandler(shortcut)
|
||||||
|
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -75,27 +76,15 @@ export function registerShortcuts(window: BrowserWindow) {
|
|||||||
if (shortcut.key.includes('zoom')) {
|
if (shortcut.key.includes('zoom')) {
|
||||||
switch (shortcut.key) {
|
switch (shortcut.key) {
|
||||||
case 'zoom_in':
|
case 'zoom_in':
|
||||||
try {
|
globalShortcut.register('CommandOrControl+=', () => shortcut.enabled && handler(window))
|
||||||
globalShortcut.register('CommandOrControl+=', () => shortcut.enabled && handler(window))
|
globalShortcut.register('CommandOrControl+numadd', () => shortcut.enabled && handler(window))
|
||||||
globalShortcut.register('CommandOrControl+numadd', () => shortcut.enabled && handler(window))
|
|
||||||
} catch (error) {
|
|
||||||
Logger.error('[ShortcutService] Failed to register zoom in shortcuts:', error)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
case 'zoom_out':
|
case 'zoom_out':
|
||||||
try {
|
globalShortcut.register('CommandOrControl+-', () => shortcut.enabled && handler(window))
|
||||||
globalShortcut.register('CommandOrControl+-', () => shortcut.enabled && handler(window))
|
globalShortcut.register('CommandOrControl+numsub', () => shortcut.enabled && handler(window))
|
||||||
globalShortcut.register('CommandOrControl+numsub', () => shortcut.enabled && handler(window))
|
|
||||||
} catch (error) {
|
|
||||||
Logger.error('[ShortcutService] Failed to register zoom out shortcuts:', error)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
case 'zoom_reset':
|
case 'zoom_reset':
|
||||||
try {
|
globalShortcut.register('CommandOrControl+0', () => shortcut.enabled && handler(window))
|
||||||
globalShortcut.register('CommandOrControl+0', () => shortcut.enabled && handler(window))
|
|
||||||
} catch (error) {
|
|
||||||
Logger.error('[ShortcutService] Failed to register zoom reset shortcut:', error)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +93,7 @@ export function registerShortcuts(window: BrowserWindow) {
|
|||||||
globalShortcut.register(accelerator, () => handler(window))
|
globalShortcut.register(accelerator, () => handler(window))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`[ShortcutService] Failed to register shortcut ${shortcut.key}:`, error)
|
Logger.error(`[ShortcutService] Failed to register shortcut ${shortcut.key}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -112,11 +101,15 @@ export function registerShortcuts(window: BrowserWindow) {
|
|||||||
const unregister = () => {
|
const unregister = () => {
|
||||||
if (window.isDestroyed()) return
|
if (window.isDestroyed()) return
|
||||||
|
|
||||||
globalShortcut.unregisterAll()
|
try {
|
||||||
|
globalShortcut.unregisterAll()
|
||||||
|
|
||||||
if (showAppAccelerator) {
|
if (showAppAccelerator) {
|
||||||
const handler = getShortcutHandler({ key: 'show_app' } as Shortcut)
|
const handler = getShortcutHandler({ key: 'show_app' } as Shortcut)
|
||||||
handler && globalShortcut.register(showAppAccelerator, () => handler(window))
|
handler && globalShortcut.register(showAppAccelerator, () => handler(window))
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('[ShortcutService] Failed to unregister shortcuts')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +122,10 @@ export function registerShortcuts(window: BrowserWindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function unregisterAllShortcuts() {
|
export function unregisterAllShortcuts() {
|
||||||
showAppAccelerator = null
|
try {
|
||||||
globalShortcut.unregisterAll()
|
showAppAccelerator = null
|
||||||
|
globalShortcut.unregisterAll()
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('[ShortcutService] Failed to unregister all shortcuts')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -465,7 +465,7 @@
|
|||||||
"reset_defaults": "Reset Defaults",
|
"reset_defaults": "Reset Defaults",
|
||||||
"reset_defaults_confirm": "Are you sure you want to reset all shortcuts?",
|
"reset_defaults_confirm": "Are you sure you want to reset all shortcuts?",
|
||||||
"press_shortcut": "Press Shortcut",
|
"press_shortcut": "Press Shortcut",
|
||||||
"alt_warning": "Mac does not support the Alt key",
|
"alt_warning": "Mac does not support Option + letters as shortcuts",
|
||||||
"reset_to_default": "Reset to Default",
|
"reset_to_default": "Reset to Default",
|
||||||
"clear_shortcut": "Clear Shortcut"
|
"clear_shortcut": "Clear Shortcut"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -465,7 +465,7 @@
|
|||||||
"reset_defaults": "Сбросить настройки по умолчанию",
|
"reset_defaults": "Сбросить настройки по умолчанию",
|
||||||
"reset_defaults_confirm": "Вы уверены, что хотите сбросить все горячие клавиши?",
|
"reset_defaults_confirm": "Вы уверены, что хотите сбросить все горячие клавиши?",
|
||||||
"press_shortcut": "Нажмите сочетание клавиш",
|
"press_shortcut": "Нажмите сочетание клавиш",
|
||||||
"alt_warning": "Mac не поддерживает Alt",
|
"alt_warning": "Mac не поддерживает Option + буквы как горячие клавиши",
|
||||||
"reset_to_default": "Сбросить настройки по умолчанию",
|
"reset_to_default": "Сбросить настройки по умолчанию",
|
||||||
"clear_shortcut": "Очистить сочетание клавиш"
|
"clear_shortcut": "Очистить сочетание клавиш"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -453,7 +453,7 @@
|
|||||||
"reset_defaults": "重置默认快捷键",
|
"reset_defaults": "重置默认快捷键",
|
||||||
"reset_defaults_confirm": "确定要重置所有快捷键吗?",
|
"reset_defaults_confirm": "确定要重置所有快捷键吗?",
|
||||||
"press_shortcut": "按下快捷键",
|
"press_shortcut": "按下快捷键",
|
||||||
"alt_warning": "Mac 系统不支持 Alt 键",
|
"alt_warning": "Mac 系统不能使用 Option + 字母作为快捷键",
|
||||||
"reset_to_default": "重置为默认",
|
"reset_to_default": "重置为默认",
|
||||||
"clear_shortcut": "清除快捷键"
|
"clear_shortcut": "清除快捷键"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -453,7 +453,7 @@
|
|||||||
"reset_defaults": "重置預設快捷鍵",
|
"reset_defaults": "重置預設快捷鍵",
|
||||||
"reset_defaults_confirm": "確定要重置所有快捷鍵嗎?",
|
"reset_defaults_confirm": "確定要重置所有快捷鍵嗎?",
|
||||||
"press_shortcut": "按下快捷鍵",
|
"press_shortcut": "按下快捷鍵",
|
||||||
"alt_warning": "Mac 系統不支持 Alt 鍵",
|
"alt_warning": "Mac 不能使用 Option + 字母作為快捷鍵",
|
||||||
"reset_to_default": "重置為預設",
|
"reset_to_default": "重置為預設",
|
||||||
"clear_shortcut": "清除快捷鍵"
|
"clear_shortcut": "清除快捷鍵"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { ClearOutlined, UndoOutlined } from '@ant-design/icons'
|
import { ClearOutlined, UndoOutlined } from '@ant-design/icons'
|
||||||
import { HStack } from '@renderer/components/Layout'
|
import { HStack } from '@renderer/components/Layout'
|
||||||
import { isMac } from '@renderer/config/constant'
|
import { isMac, isWindows } from '@renderer/config/constant'
|
||||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||||
import { initialState, resetShortcuts, toggleShortcut, updateShortcut } from '@renderer/store/shortcuts'
|
import { initialState, resetShortcuts, toggleShortcut, updateShortcut } from '@renderer/store/shortcuts'
|
||||||
@ -84,7 +84,7 @@ const ShortcutSettings: FC = () => {
|
|||||||
case 'Ctrl':
|
case 'Ctrl':
|
||||||
return isMac ? '⌃' : 'Ctrl'
|
return isMac ? '⌃' : 'Ctrl'
|
||||||
case 'Command':
|
case 'Command':
|
||||||
return '⌘'
|
return isMac ? '⌘' : isWindows ? 'Win' : 'Super'
|
||||||
case 'Alt':
|
case 'Alt':
|
||||||
return isMac ? '⌥' : 'Alt'
|
return isMac ? '⌥' : 'Alt'
|
||||||
case 'Shift':
|
case 'Shift':
|
||||||
@ -111,7 +111,7 @@ const ShortcutSettings: FC = () => {
|
|||||||
|
|
||||||
const key = e.key
|
const key = e.key
|
||||||
|
|
||||||
if (!['Control', 'Alt', 'Shift', 'Meta', 'Process'].includes(key) && key.length === 1) {
|
if (key.length === 1 && !['Control', 'Alt', 'Shift', 'Meta'].includes(key)) {
|
||||||
keys.push(key.toUpperCase())
|
keys.push(key.toUpperCase())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user