Debounce hotkey set to improve performance
This commit is contained in:
parent
5eea3d7e01
commit
cf32a7ff21
1 changed files with 12 additions and 6 deletions
|
@ -1,9 +1,10 @@
|
||||||
import { Group } from '@mantine/core';
|
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
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 { RiDeleteBinLine, RiEditLine, RiKeyboardBoxLine } from 'react-icons/ri';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Button, TextInput, Checkbox } from '/@/renderer/components';
|
import { Button, TextInput, Checkbox } from '/@/renderer/components';
|
||||||
import isElectron from 'is-electron';
|
|
||||||
import { BindingActions, useHotkeySettings, useSettingsStoreActions } from '/@/renderer/store';
|
import { BindingActions, useHotkeySettings, useSettingsStoreActions } from '/@/renderer/store';
|
||||||
import { SettingsOptions } from '/@/renderer/features/settings/components/settings-option';
|
import { SettingsOptions } from '/@/renderer/features/settings/components/settings-option';
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ export const HotkeyManagerSettings = () => {
|
||||||
const { setSettings } = useSettingsStoreActions();
|
const { setSettings } = useSettingsStoreActions();
|
||||||
const [selected, setSelected] = useState<BindingActions | null>(null);
|
const [selected, setSelected] = useState<BindingActions | null>(null);
|
||||||
|
|
||||||
const handleSetHotkey = useCallback(
|
const debouncedSetHotkey = debounce(
|
||||||
(binding: BindingActions, e: React.KeyboardEvent<HTMLInputElement>) => {
|
(binding: BindingActions, e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const IGNORED_KEYS = ['Control', 'Alt', 'Shift', 'Meta', ' ', 'Escape'];
|
const IGNORED_KEYS = ['Control', 'Alt', 'Shift', 'Meta', ' ', 'Escape'];
|
||||||
|
@ -85,9 +86,16 @@ export const HotkeyManagerSettings = () => {
|
||||||
|
|
||||||
ipc?.send('set-global-shortcuts', updatedBindings);
|
ipc?.send('set-global-shortcuts', updatedBindings);
|
||||||
},
|
},
|
||||||
[bindings, globalMediaHotkeys, setSettings],
|
20,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleSetHotkey = useCallback(debouncedSetHotkey, [
|
||||||
|
bindings,
|
||||||
|
globalMediaHotkeys,
|
||||||
|
setSettings,
|
||||||
|
debouncedSetHotkey,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleSetGlobalHotkey = useCallback(
|
const handleSetGlobalHotkey = useCallback(
|
||||||
(binding: BindingActions, e: React.ChangeEvent<HTMLInputElement>) => {
|
(binding: BindingActions, e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const updatedBindings = {
|
const updatedBindings = {
|
||||||
|
@ -95,8 +103,6 @@ export const HotkeyManagerSettings = () => {
|
||||||
[binding]: { ...bindings[binding], isGlobal: e.currentTarget.checked },
|
[binding]: { ...bindings[binding], isGlobal: e.currentTarget.checked },
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('updatedBindings :>> ', updatedBindings);
|
|
||||||
|
|
||||||
setSettings({
|
setSettings({
|
||||||
hotkeys: {
|
hotkeys: {
|
||||||
bindings: updatedBindings,
|
bindings: updatedBindings,
|
||||||
|
|
Reference in a new issue