mirror of
https://github.com/jeffvli/feishin.git
synced 2024-11-20 14:37:06 +01:00
Debounce hotkey set to improve performance
This commit is contained in:
parent
5eea3d7e01
commit
cf32a7ff21
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user