1616using Flow . Launcher . Infrastructure . Logger ;
1717using Flow . Launcher . Infrastructure . UserSettings ;
1818using Flow . Launcher . Plugin ;
19+ using Flow . Launcher . Plugin . SharedModels ;
1920using Microsoft . Win32 ;
2021
2122namespace Flow . Launcher . Core . Resource
@@ -81,11 +82,6 @@ public Theme(IPublicAPI publicAPI, Settings settings)
8182
8283 #region Theme Resources
8384
84- public string GetCurrentTheme ( )
85- {
86- return _settings . Theme ;
87- }
88-
8985 private void MakeSureThemeDirectoriesExist ( )
9086 {
9187 foreach ( var dir in _themeDirectories . Where ( dir => ! Directory . Exists ( dir ) ) )
@@ -127,7 +123,7 @@ public void UpdateFonts()
127123 try
128124 {
129125 // Load a ResourceDictionary for the specified theme.
130- var themeName = GetCurrentTheme ( ) ;
126+ var themeName = _settings . Theme ;
131127 var dict = GetThemeResourceDictionary ( themeName ) ;
132128
133129 // Apply font settings to the theme resource.
@@ -330,7 +326,7 @@ private ResourceDictionary GetResourceDictionary(string theme)
330326
331327 private ResourceDictionary GetCurrentResourceDictionary ( )
332328 {
333- return GetResourceDictionary ( GetCurrentTheme ( ) ) ;
329+ return GetResourceDictionary ( _settings . Theme ) ;
334330 }
335331
336332 private ThemeData GetThemeDataFromPath ( string path )
@@ -383,9 +379,20 @@ private string GetThemePath(string themeName)
383379
384380 #endregion
385381
386- #region Load & Change
382+ #region Get & Change Theme
383+
384+ public ThemeData GetCurrentTheme ( )
385+ {
386+ var themes = GetAvailableThemes ( ) ;
387+ var matchingTheme = themes . FirstOrDefault ( t => t . FileNameWithoutExtension == _settings . Theme ) ;
388+ if ( matchingTheme == null )
389+ {
390+ Log . Warn ( $ "No matching theme found for '{ _settings . Theme } '. Falling back to the first available theme.") ;
391+ }
392+ return matchingTheme ?? themes . FirstOrDefault ( ) ;
393+ }
387394
388- public List < ThemeData > LoadAvailableThemes ( )
395+ public List < ThemeData > GetAvailableThemes ( )
389396 {
390397 List < ThemeData > themes = new List < ThemeData > ( ) ;
391398 foreach ( var themeDirectory in _themeDirectories )
@@ -403,7 +410,7 @@ public List<ThemeData> LoadAvailableThemes()
403410 public bool ChangeTheme ( string theme = null )
404411 {
405412 if ( string . IsNullOrEmpty ( theme ) )
406- theme = GetCurrentTheme ( ) ;
413+ theme = _settings . Theme ;
407414
408415 string path = GetThemePath ( theme ) ;
409416 try
@@ -426,7 +433,7 @@ public bool ChangeTheme(string theme = null)
426433
427434 BlurEnabled = IsBlurTheme ( ) ;
428435
429- // Can only apply blur but here also apply drop shadow effect to avoid possible drop shadow effect issues
436+ // Apply blur and drop shadow effect so that we do not need to call it again
430437 _ = RefreshFrameAsync ( ) ;
431438
432439 return true ;
@@ -591,7 +598,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
591598 {
592599 AutoDropShadow ( useDropShadowEffect ) ;
593600 }
594- SetBlurForWindow ( GetCurrentTheme ( ) , backdropType ) ;
601+ SetBlurForWindow ( _settings . Theme , backdropType ) ;
595602
596603 if ( ! BlurEnabled )
597604 {
@@ -610,7 +617,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
610617 // Get the actual backdrop type and drop shadow effect settings
611618 var ( backdropType , _) = GetActualValue ( ) ;
612619
613- SetBlurForWindow ( GetCurrentTheme ( ) , backdropType ) ;
620+ SetBlurForWindow ( _settings . Theme , backdropType ) ;
614621 } , DispatcherPriority . Render ) ;
615622 }
616623
@@ -898,11 +905,5 @@ private static bool IsBlurTheme()
898905 }
899906
900907 #endregion
901-
902- #region Classes
903-
904- public record ThemeData ( string FileNameWithoutExtension , string Name , bool ? IsDark = null , bool ? HasBlur = null ) ;
905-
906- #endregion
907908 }
908909}
0 commit comments