|
1 | 1 | import { DependencyList, useCallback, useEffect, useState } from 'react'; |
2 | 2 |
|
3 | | -import { mainStore } from '$stores/MainStore'; |
| 3 | +import { defaultHotkeys } from '$data/hotkeys'; |
| 4 | +import { useConfigStore } from '$store/config'; |
4 | 5 | import { IS_MAC } from '$utils/config'; |
5 | 6 |
|
6 | 7 | let disableHotkeys = false; |
@@ -130,11 +131,30 @@ const isHotkeyMatchingKeyboardEvent = ( |
130 | 131 | return false; |
131 | 132 | }; |
132 | 133 |
|
| 134 | +let parsedHotkeys: Record<string, ParsedHotkey> = {}; |
| 135 | + |
| 136 | +useConfigStore.subscribe(state => { |
| 137 | + const overrides = state.data?.app?.hotkeys; |
| 138 | + const hotkeys = { ...defaultHotkeys }; |
| 139 | + |
| 140 | + if (overrides) { |
| 141 | + for (const [key, value] of Object.entries(overrides)) { |
| 142 | + if (value && key in hotkeys) { |
| 143 | + hotkeys[key] = value; |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + parsedHotkeys = Object.fromEntries( |
| 149 | + Object.entries(hotkeys).map(([id, keys]) => [id, parseHotkey(keys)]), |
| 150 | + ); |
| 151 | +}); |
| 152 | + |
133 | 153 | export function matchHotkey( |
134 | 154 | e: KeyboardEvent | React.KeyboardEvent, |
135 | 155 | group?: string, |
136 | 156 | ) { |
137 | | - for (const [id, parsed] of Object.entries(mainStore.hotkeys)) { |
| 157 | + for (const [id, parsed] of Object.entries(parsedHotkeys)) { |
138 | 158 | if (group && !id.startsWith(`${group}_`)) { |
139 | 159 | continue; |
140 | 160 | } |
@@ -240,7 +260,7 @@ export function useHotkey( |
240 | 260 | dependencies?: DependencyList, |
241 | 261 | ) { |
242 | 262 | useEffect(() => { |
243 | | - if (!mainStore.hotkeys[id]) { |
| 263 | + if (!defaultHotkeys[id]) { |
244 | 264 | console.warn(`Unregistered hotkey ID: ${id}`); |
245 | 265 | } |
246 | 266 |
|
|
0 commit comments