@@ -847,19 +847,27 @@ export class SettingsManager {
847847 // Remove existing theme attributes
848848 html . removeAttribute ( 'data-theme' ) ;
849849
850- // Apply new theme
851- html . setAttribute ( 'data-theme' , theme ) ;
850+ // Determine the actual theme to apply
851+ let actualTheme = theme ;
852+ if ( theme === 'auto' ) {
853+ // For auto mode, detect system preference and apply the actual theme
854+ actualTheme = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ;
855+ console . log ( `🎨 Auto theme detected system preference: ${ actualTheme } ` ) ;
856+ }
857+
858+ // Apply the actual theme (never "auto")
859+ html . setAttribute ( 'data-theme' , actualTheme ) ;
852860
853861 // Store theme preference in localStorage for quick access
854- localStorage . setItem ( 'theme-preference' , theme ) ;
862+ localStorage . setItem ( 'theme-preference' , theme ) ; // Store user preference (could be "auto")
855863
856864 // Update settings object and save immediately to prevent loss on app close
857865 if ( this . settings && this . settings . appearance ) {
858- this . settings . appearance . theme = theme ;
866+ this . settings . appearance . theme = theme ; // Store user preference (could be "auto")
859867 try {
860868 // Save immediately to file
861869 await invoke ( 'save_settings' , { settings : this . settings } ) ;
862- console . log ( `🎨 Theme saved: ${ theme } ` ) ;
870+ console . log ( `🎨 Theme preference saved: ${ theme } , actual theme applied: ${ actualTheme } ` ) ;
863871 } catch ( error ) {
864872 console . error ( 'Failed to save theme setting:' , error ) ;
865873 }
@@ -872,7 +880,7 @@ export class SettingsManager {
872880 this . removeSystemThemeListener ( ) ;
873881 }
874882
875- console . log ( `🎨 Theme applied : ${ theme } ` ) ;
883+ console . log ( `🎨 Theme preference : ${ theme } , actual theme applied: ${ actualTheme } ` ) ;
876884
877885 // Update timer theme compatibility when color mode changes
878886 this . updateTimerThemeCompatibility ( ) ;
@@ -885,10 +893,19 @@ export class SettingsManager {
885893 // Create new listener
886894 this . systemThemeMediaQuery = window . matchMedia ( '(prefers-color-scheme: dark)' ) ;
887895 this . systemThemeListener = ( e ) => {
888- console . log ( `🎨 System theme changed: ${ e . matches ? 'dark' : 'light' } ` ) ;
889- // Theme is automatically applied via CSS media queries when data-theme="auto"
890- // Update timer theme compatibility when system theme changes
891- this . updateTimerThemeCompatibility ( ) ;
896+ const newSystemTheme = e . matches ? 'dark' : 'light' ;
897+ console . log ( `🎨 System theme changed: ${ newSystemTheme } ` ) ;
898+
899+ // Only apply if current preference is "auto"
900+ const currentPreference = this . settings ?. appearance ?. theme || 'auto' ;
901+ if ( currentPreference === 'auto' ) {
902+ const html = document . documentElement ;
903+ html . setAttribute ( 'data-theme' , newSystemTheme ) ;
904+ console . log ( `🎨 Auto theme updated to: ${ newSystemTheme } ` ) ;
905+
906+ // Update timer theme compatibility when system theme changes
907+ this . updateTimerThemeCompatibility ( ) ;
908+ }
892909 } ;
893910
894911 this . systemThemeMediaQuery . addEventListener ( 'change' , this . systemThemeListener ) ;
@@ -907,10 +924,21 @@ export class SettingsManager {
907924 const currentTheme = document . documentElement . getAttribute ( 'data-theme' ) ;
908925 const storedTheme = localStorage . getItem ( 'theme-preference' ) ;
909926
910- // If early theme was set and matches localStorage, keep it
927+ // If early theme was set and matches localStorage, check if we need to process it
911928 if ( currentTheme && storedTheme && currentTheme === storedTheme ) {
912- console . log ( `🎨 Keeping early initialized theme: ${ currentTheme } ` ) ;
929+ console . log ( `🎨 Early initialized theme found: ${ currentTheme } ` ) ;
930+
931+ // If the stored theme is "auto", we need to apply the correct auto logic
932+ // because data-theme should never be "auto" - it should be "light" or "dark"
933+ if ( storedTheme === 'auto' ) {
934+ console . log ( `🎨 Converting auto theme to actual theme` ) ;
935+ await this . applyTheme ( 'auto' ) ; // This will set data-theme to light/dark
936+ return ;
937+ }
913938
939+ // For non-auto themes, keep the early initialization
940+ console . log ( `🎨 Keeping early initialized theme: ${ currentTheme } ` ) ;
941+
914942 // Update settings to match current theme
915943 if ( this . settings && this . settings . appearance ) {
916944 this . settings . appearance . theme = currentTheme ;
@@ -921,11 +949,6 @@ export class SettingsManager {
921949 console . error ( 'Failed to update theme in settings:' , error ) ;
922950 }
923951 }
924-
925- // Setup listeners for auto theme if needed
926- if ( currentTheme === 'auto' ) {
927- this . setupSystemThemeListener ( ) ;
928- }
929952 return ;
930953 }
931954
@@ -994,15 +1017,9 @@ export class SettingsManager {
9941017 // Timer Theme Management Functions
9951018 getCurrentColorMode ( ) {
9961019 const currentTheme = document . documentElement . getAttribute ( 'data-theme' ) ;
997-
998- if ( currentTheme === 'light' ) return 'light' ;
999- if ( currentTheme === 'dark' ) return 'dark' ;
1000- if ( currentTheme === 'auto' ) {
1001- // Check system preference
1002- return window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ;
1003- }
1004-
1005- return 'light' ; // default fallback
1020+
1021+ // Since data-theme is now always 'light' or 'dark' (never 'auto'), this is simpler
1022+ return currentTheme === 'dark' ? 'dark' : 'light' ;
10061023 }
10071024
10081025 async initializeTimerTheme ( ) {
0 commit comments