diff --git a/src/renderer/features/settings/components/hotkeys/hotkey-manager-settings.tsx b/src/renderer/features/settings/components/hotkeys/hotkey-manager-settings.tsx index c8138f27..d933f945 100644 --- a/src/renderer/features/settings/components/hotkeys/hotkey-manager-settings.tsx +++ b/src/renderer/features/settings/components/hotkeys/hotkey-manager-settings.tsx @@ -1,9 +1,10 @@ -import { Group } from '@mantine/core'; import { useCallback, useMemo, useState } from 'react'; +import { Group } from '@mantine/core'; +import isElectron from 'is-electron'; +import debounce from 'lodash/debounce'; import { RiDeleteBinLine, RiEditLine, RiKeyboardBoxLine } from 'react-icons/ri'; import styled from 'styled-components'; import { Button, TextInput, Checkbox } from '/@/renderer/components'; -import isElectron from 'is-electron'; import { BindingActions, useHotkeySettings, useSettingsStoreActions } from '/@/renderer/store'; import { SettingsOptions } from '/@/renderer/features/settings/components/settings-option'; @@ -46,7 +47,7 @@ export const HotkeyManagerSettings = () => { const { setSettings } = useSettingsStoreActions(); const [selected, setSelected] = useState(null); - const handleSetHotkey = useCallback( + const debouncedSetHotkey = debounce( (binding: BindingActions, e: React.KeyboardEvent) => { e.preventDefault(); const IGNORED_KEYS = ['Control', 'Alt', 'Shift', 'Meta', ' ', 'Escape']; @@ -85,9 +86,16 @@ export const HotkeyManagerSettings = () => { ipc?.send('set-global-shortcuts', updatedBindings); }, - [bindings, globalMediaHotkeys, setSettings], + 20, ); + const handleSetHotkey = useCallback(debouncedSetHotkey, [ + bindings, + globalMediaHotkeys, + setSettings, + debouncedSetHotkey, + ]); + const handleSetGlobalHotkey = useCallback( (binding: BindingActions, e: React.ChangeEvent) => { const updatedBindings = { @@ -95,8 +103,6 @@ export const HotkeyManagerSettings = () => { [binding]: { ...bindings[binding], isGlobal: e.currentTarget.checked }, }; - console.log('updatedBindings :>> ', updatedBindings); - setSettings({ hotkeys: { bindings: updatedBindings,