Debounce hotkey set to improve performance

This commit is contained in:
jeffvli 2023-05-14 01:57:42 -07:00
parent 5eea3d7e01
commit cf32a7ff21

View File

@ -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<BindingActions | null>(null);
const handleSetHotkey = useCallback(
const debouncedSetHotkey = debounce(
(binding: BindingActions, e: React.KeyboardEvent<HTMLInputElement>) => {
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<HTMLInputElement>) => {
const updatedBindings = {
@ -95,8 +103,6 @@ export const HotkeyManagerSettings = () => {
[binding]: { ...bindings[binding], isGlobal: e.currentTarget.checked },
};
console.log('updatedBindings :>> ', updatedBindings);
setSettings({
hotkeys: {
bindings: updatedBindings,