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