From f58c95057aa3394d1215c432dfd73d85c804e94f Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Mon, 3 Jun 2024 13:25:42 +0600 Subject: [PATCH] Theme metadata adjustments --- Flow.Launcher.Core/Resource/Theme.cs | 45 +++++++++---------- .../ViewModels/SettingsPaneThemeViewModel.cs | 4 +- .../SettingPages/Views/SettingsPaneTheme.xaml | 4 +- Flow.Launcher/Themes/BlurBlack Darker.xaml | 2 +- Flow.Launcher/Themes/BlurBlack.xaml | 4 +- Flow.Launcher/Themes/BlurWhite.xaml | 2 +- Flow.Launcher/Themes/Circle System.xaml | 4 +- Flow.Launcher/Themes/Win10System.xaml | 2 +- Flow.Launcher/Themes/Win11Light.xaml | 4 +- 9 files changed, 35 insertions(+), 36 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index a442eae64..c3a3e9891 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -18,6 +18,10 @@ namespace Flow.Launcher.Core.Resource { public class Theme { + private const string ThemeMetadataNamePrefix = "Name:"; + private const string ThemeMetadataIsDarkPrefix = "IsDark:"; + private const string ThemeMetadataHasBlurPrefix = "HasBlur:"; + private const int ShadowExtraMargin = 32; private readonly List _themeDirectories = new List(); @@ -80,14 +84,14 @@ namespace Flow.Launcher.Core.Resource { if (string.IsNullOrEmpty(path)) throw new DirectoryNotFoundException("Theme path can't be found <{path}>"); - + // reload all resources even if the theme itself hasn't changed in order to pickup changes // to things like fonts UpdateResourceDictionary(GetResourceDictionary(theme)); - + Settings.Theme = theme; - + //always allow re-loading default theme, in case of failure of switching to a new theme from default theme if (_oldTheme != theme || theme == defaultTheme) { @@ -149,7 +153,7 @@ namespace Flow.Launcher.Core.Resource public ResourceDictionary GetResourceDictionary(string theme) { var dict = GetThemeResourceDictionary(theme); - + if (dict["QueryBoxStyle"] is Style queryBoxStyle && dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle) { @@ -188,7 +192,7 @@ namespace Flow.Launcher.Core.Resource Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; Array.ForEach( - new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o + new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); } @@ -246,34 +250,27 @@ namespace Flow.Launcher.Core.Resource return new ThemeData(extensionlessName, extensionlessName); var commentLines = reader.Value.Trim().Split('\n').Select(v => v.Trim()); - var themeData = new ThemeData(extensionlessName, extensionlessName); + + var name = extensionlessName; + bool? isDark = null; + bool? hasBlur = null; foreach (var line in commentLines) { - if (line.StartsWith("Name:", StringComparison.OrdinalIgnoreCase)) + if (line.StartsWith(ThemeMetadataNamePrefix, StringComparison.OrdinalIgnoreCase)) { - themeData = themeData with { Name = line.Remove(0, "Name:".Length).Trim() }; + name = line.Remove(0, ThemeMetadataNamePrefix.Length).Trim(); } - else if (line.StartsWith("IsDark:", StringComparison.OrdinalIgnoreCase)) + else if (line.StartsWith(ThemeMetadataIsDarkPrefix, StringComparison.OrdinalIgnoreCase)) { - themeData = themeData with - { - IsDark = bool.Parse( - line.Remove(0, "IsDark:".Length).Trim() - ) - }; + isDark = bool.Parse(line.Remove(0, ThemeMetadataIsDarkPrefix.Length).Trim()); } - else if (line.StartsWith("IsBlur:", StringComparison.OrdinalIgnoreCase)) + else if (line.StartsWith(ThemeMetadataHasBlurPrefix, StringComparison.OrdinalIgnoreCase)) { - themeData = themeData with - { - IsBlur = bool.Parse( - line.Remove(0, "IsBlur:".Length).Trim() - ) - }; + hasBlur = bool.Parse(line.Remove(0, ThemeMetadataHasBlurPrefix.Length).Trim()); } } - return themeData; + return new ThemeData(extensionlessName, name, isDark, hasBlur); } private string GetThemePath(string themeName) @@ -452,6 +449,6 @@ namespace Flow.Launcher.Core.Resource } #endregion - public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? IsBlur = null); + public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? HasBlur = null); } } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 64b138a0a..8b9f069ce 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -93,7 +93,9 @@ public partial class SettingsPaneThemeViewModel : BaseModel get => Settings.ResultSubItemFontSize; set => Settings.ResultSubItemFontSize = value; } - public List Themes => ThemeManager.Instance.LoadAvailableThemes(); + + private List _themes; + public List Themes => _themes ??= ThemeManager.Instance.LoadAvailableThemes(); public class ColorScheme diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml index b3fa0a1b8..e21e44918 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml @@ -396,7 +396,7 @@ VerticalAlignment="Center" FontSize="12" Glyph="" - Visibility="{Binding SelectedTheme.IsBlur, Converter={StaticResource BoolToVisibilityConverter}}" /> + Visibility="{Binding SelectedTheme.HasBlur, Converter={StaticResource BoolToVisibilityConverter}}" /> @@ -442,7 +442,7 @@ VerticalAlignment="Center" FontSize="12" Glyph="" - Visibility="{Binding IsBlur, Converter={StaticResource BoolToVisibilityConverter}}" /> + Visibility="{Binding HasBlur, Converter={StaticResource BoolToVisibilityConverter}}" /> diff --git a/Flow.Launcher/Themes/BlurBlack Darker.xaml b/Flow.Launcher/Themes/BlurBlack Darker.xaml index 714dd73c9..286419c70 100644 --- a/Flow.Launcher/Themes/BlurBlack Darker.xaml +++ b/Flow.Launcher/Themes/BlurBlack Darker.xaml @@ -1,7 +1,7 @@  - \ No newline at end of file + diff --git a/Flow.Launcher/Themes/BlurWhite.xaml b/Flow.Launcher/Themes/BlurWhite.xaml index 75f61ee47..a13f3bfcc 100644 --- a/Flow.Launcher/Themes/BlurWhite.xaml +++ b/Flow.Launcher/Themes/BlurWhite.xaml @@ -1,7 +1,7 @@  - \ No newline at end of file + diff --git a/Flow.Launcher/Themes/Win10System.xaml b/Flow.Launcher/Themes/Win10System.xaml index 1b785329f..0b041bc09 100644 --- a/Flow.Launcher/Themes/Win10System.xaml +++ b/Flow.Launcher/Themes/Win10System.xaml @@ -1,7 +1,7 @@ - \ No newline at end of file +