@@ -10,8 +10,8 @@ import './App.css';
1010// Falls back gracefully for browser mode
1111const electronAPI = window . electronAPI || null ;
1212
13- // Load settings from localStorage or use defaults
14- const loadSettings = ( ) => {
13+ // Load settings from localStorage or use defaults (browser fallback)
14+ const loadSettingsFromLocalStorage = ( ) => {
1515 try {
1616 const saved = localStorage . getItem ( 'itc-settings' ) ;
1717 if ( saved ) {
@@ -23,8 +23,8 @@ const loadSettings = () => {
2323 return defaultSettings ;
2424} ;
2525
26- // Save settings to localStorage
27- const saveSettings = ( settings ) => {
26+ // Save settings to localStorage (browser fallback)
27+ const saveSettingsToLocalStorage = ( settings ) => {
2828 try {
2929 localStorage . setItem ( 'itc-settings' , JSON . stringify ( settings ) ) ;
3030 } catch ( err ) {
@@ -35,10 +35,10 @@ const saveSettings = (settings) => {
3535function App ( ) {
3636 const [ statusMessage , setStatusMessage ] = useState ( '' ) ;
3737 const [ meaningText , setMeaningText ] = useState ( '' ) ;
38- const [ appVersion , setAppVersion ] = useState ( '0.2.0 ' ) ;
38+ const [ appVersion , setAppVersion ] = useState ( '0.2.1 ' ) ;
3939 const [ showDocs , setShowDocs ] = useState ( false ) ;
4040 const [ showSettings , setShowSettings ] = useState ( false ) ;
41- const [ settings , setSettings ] = useState ( loadSettings ) ;
41+ const [ settings , setSettings ] = useState ( loadSettingsFromLocalStorage ) ;
4242 const [ globalNotification , setGlobalNotification ] = useState ( '' ) ;
4343 const [ updateStatus , setUpdateStatus ] = useState ( '' ) ;
4444
@@ -59,9 +59,34 @@ function App() {
5959 fetchVersion ( ) ;
6060 } , [ ] ) ;
6161
62+ // Load settings from Electron main process when available
63+ useEffect ( ( ) => {
64+ const loadElectronSettings = async ( ) => {
65+ if ( ! electronAPI || ! electronAPI . isElectron || ! electronAPI . getSettings ) return ;
66+
67+ try {
68+ const result = await electronAPI . getSettings ( ) ;
69+ if ( result && result . success && result . settings ) {
70+ setSettings ( result . settings ) ;
71+ }
72+ } catch ( err ) {
73+ console . error ( 'Failed to load Electron settings:' , err ) ;
74+ }
75+ } ;
76+
77+ loadElectronSettings ( ) ;
78+ } , [ ] ) ;
79+
6280 // Save settings whenever they change
6381 useEffect ( ( ) => {
64- saveSettings ( settings ) ;
82+ if ( electronAPI && electronAPI . isElectron && electronAPI . setSettings ) {
83+ electronAPI . setSettings ( settings ) . catch ( ( err ) => {
84+ console . error ( 'Failed to save Electron settings:' , err ) ;
85+ } ) ;
86+ return ;
87+ }
88+
89+ saveSettingsToLocalStorage ( settings ) ;
6590 } , [ settings ] ) ;
6691
6792 // Apply theme from settings
@@ -77,6 +102,10 @@ function App() {
77102 // Unregister all first to clean up
78103 await electronAPI . unregisterAllGlobalShortcuts ( ) ;
79104
105+ if ( ! settings . globalShortcutsEnabled ) {
106+ return ;
107+ }
108+
80109 // Register each shortcut that has global enabled
81110 for ( const shortcut of settings . shortcuts ) {
82111 if ( shortcut . global ) {
@@ -99,7 +128,7 @@ function App() {
99128 return ( ) => {
100129 electronAPI . unregisterAllGlobalShortcuts ( ) ;
101130 } ;
102- } , [ settings . shortcuts ] ) ;
131+ } , [ settings . shortcuts , settings . globalShortcutsEnabled ] ) ;
103132
104133 // Listen for global shortcut triggered events
105134 useEffect ( ( ) => {
@@ -377,7 +406,7 @@ function App() {
377406 { showSettings && (
378407 < Settings
379408 settings = { settings }
380- onSettingsChange = { handleSettingsChange }
409+ onSave = { handleSettingsChange }
381410 onClose = { closeSettings }
382411 />
383412 ) }
0 commit comments