16
16
using Flow . Launcher . Infrastructure . Logger ;
17
17
using Flow . Launcher . Infrastructure . UserSettings ;
18
18
using Flow . Launcher . Plugin ;
19
+ using Flow . Launcher . Plugin . SharedModels ;
19
20
using Microsoft . Win32 ;
20
21
21
22
namespace Flow . Launcher . Core . Resource
@@ -81,11 +82,6 @@ public Theme(IPublicAPI publicAPI, Settings settings)
81
82
82
83
#region Theme Resources
83
84
84
- public string GetCurrentTheme ( )
85
- {
86
- return _settings . Theme ;
87
- }
88
-
89
85
private void MakeSureThemeDirectoriesExist ( )
90
86
{
91
87
foreach ( var dir in _themeDirectories . Where ( dir => ! Directory . Exists ( dir ) ) )
@@ -127,7 +123,7 @@ public void UpdateFonts()
127
123
try
128
124
{
129
125
// Load a ResourceDictionary for the specified theme.
130
- var themeName = GetCurrentTheme ( ) ;
126
+ var themeName = _settings . Theme ;
131
127
var dict = GetThemeResourceDictionary ( themeName ) ;
132
128
133
129
// Apply font settings to the theme resource.
@@ -330,7 +326,7 @@ private ResourceDictionary GetResourceDictionary(string theme)
330
326
331
327
private ResourceDictionary GetCurrentResourceDictionary ( )
332
328
{
333
- return GetResourceDictionary ( GetCurrentTheme ( ) ) ;
329
+ return GetResourceDictionary ( _settings . Theme ) ;
334
330
}
335
331
336
332
private ThemeData GetThemeDataFromPath ( string path )
@@ -383,9 +379,20 @@ private string GetThemePath(string themeName)
383
379
384
380
#endregion
385
381
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
+ }
387
394
388
- public List < ThemeData > LoadAvailableThemes ( )
395
+ public List < ThemeData > GetAvailableThemes ( )
389
396
{
390
397
List < ThemeData > themes = new List < ThemeData > ( ) ;
391
398
foreach ( var themeDirectory in _themeDirectories )
@@ -403,7 +410,7 @@ public List<ThemeData> LoadAvailableThemes()
403
410
public bool ChangeTheme ( string theme = null )
404
411
{
405
412
if ( string . IsNullOrEmpty ( theme ) )
406
- theme = GetCurrentTheme ( ) ;
413
+ theme = _settings . Theme ;
407
414
408
415
string path = GetThemePath ( theme ) ;
409
416
try
@@ -426,7 +433,7 @@ public bool ChangeTheme(string theme = null)
426
433
427
434
BlurEnabled = IsBlurTheme ( ) ;
428
435
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
430
437
_ = RefreshFrameAsync ( ) ;
431
438
432
439
return true ;
@@ -591,7 +598,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
591
598
{
592
599
AutoDropShadow ( useDropShadowEffect ) ;
593
600
}
594
- SetBlurForWindow ( GetCurrentTheme ( ) , backdropType ) ;
601
+ SetBlurForWindow ( _settings . Theme , backdropType ) ;
595
602
596
603
if ( ! BlurEnabled )
597
604
{
@@ -610,7 +617,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
610
617
// Get the actual backdrop type and drop shadow effect settings
611
618
var ( backdropType , _) = GetActualValue ( ) ;
612
619
613
- SetBlurForWindow ( GetCurrentTheme ( ) , backdropType ) ;
620
+ SetBlurForWindow ( _settings . Theme , backdropType ) ;
614
621
} , DispatcherPriority . Render ) ;
615
622
}
616
623
@@ -898,11 +905,5 @@ private static bool IsBlurTheme()
898
905
}
899
906
900
907
#endregion
901
-
902
- #region Classes
903
-
904
- public record ThemeData ( string FileNameWithoutExtension , string Name , bool ? IsDark = null , bool ? HasBlur = null ) ;
905
-
906
- #endregion
907
908
}
908
909
}
0 commit comments