@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
55import { ShortcutProps } from '@renderer/libs/device/keyboard' ;
66import { Shortcut } from './shortcut' ;
77import { KeyboardShortcutCustom } from './shortcut-custom' ;
8+ import { getShortcuts , setShortcuts } from '@renderer/libs/storage' ;
89
910export const KeyboardShortcutsMenu = ( ) => {
1011 const { t } = useTranslation ( ) ;
@@ -30,35 +31,28 @@ export const KeyboardShortcutsMenu = () => {
3031
3132 const addShortcut = ( shortcut : ShortcutProps ) => {
3233 if ( shortcut == null ) return ;
33-
34- let shortcuts = localStorage . getItem ( "shortcuts" ) ;
35- if ( shortcuts === null ) {
36- shortcuts = "[]" ;
37- }
38-
39- const shortcutsObject : ShortcutProps [ ] = JSON . parse ( shortcuts ) ;
40- shortcutsObject . push ( shortcut ) ;
41- localStorage . setItem ( "shortcuts" , JSON . stringify ( shortcutsObject ) ) ;
42- setStoredShortcuts ( shortcutsObject ) ;
34+ const shortcuts = getShortcuts ( ) ;
35+ shortcuts . push ( shortcut ) ;
36+ setStoredShortcuts ( shortcuts ) ;
37+ setShortcuts ( shortcuts ) ;
4338 }
4439
4540 const removeShortcut = ( indexToRemove : number ) => {
4641 const newShortcuts = storedShortcuts . filter (
4742 ( _ , index ) => index !== indexToRemove
4843 ) ;
49- localStorage . setItem ( "shortcuts" , JSON . stringify ( newShortcuts ) ) ;
5044 setStoredShortcuts ( newShortcuts ) ;
45+ setShortcuts ( newShortcuts ) ;
5146 }
5247
5348 useEffect ( ( ) => {
54- const shortcuts = localStorage . getItem ( "shortcuts" ) ;
55- if ( shortcuts === null ) {
49+ const shortcuts = getShortcuts ( ) ;
50+ if ( shortcuts . length === 0 ) {
5651 predefinedShortcuts . forEach ( shortcut => {
5752 addShortcut ( shortcut ) ;
5853 } )
5954 } else {
60- const shortcutsObject : ShortcutProps [ ] = JSON . parse ( shortcuts ) ;
61- setStoredShortcuts ( shortcutsObject ) ;
55+ setStoredShortcuts ( shortcuts ) ;
6256 }
6357 } , [ ] ) ;
6458
0 commit comments