From d099a392c5cbf91157587791fac2e37b2139f26e Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Wed, 12 Mar 2025 22:23:52 +0800 Subject: [PATCH] Fix theme change drop shadow effect issue & Add theme description --- .../Flow.Launcher.Plugin.Sys/ThemeSelector.cs | 86 ++++++++++++++++--- 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index 70aa74d77..066f62c4e 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -2,6 +2,7 @@ using System.Linq; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Core.Resource; +using Flow.Launcher.Infrastructure.UserSettings; namespace Flow.Launcher.Plugin.Sys { @@ -9,9 +10,56 @@ namespace Flow.Launcher.Plugin.Sys { public const string Keyword = "fltheme"; + private readonly Settings _settings; private readonly Theme _theme; private readonly PluginInitContext _context; + #region Theme Selection + + // Theme select codes from SettingsPaneThemeViewModel.cs + + private Theme.ThemeData _selectedTheme; + private Theme.ThemeData SelectedTheme + { + get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == _theme.CurrentTheme); + set + { + _selectedTheme = value; + _theme.ChangeTheme(value.FileNameWithoutExtension); + + if (_theme.BlurEnabled && _settings.UseDropShadowEffect) + DropShadowEffect = false; + } + } + + private List Themes => _theme.LoadAvailableThemes(); + + private bool DropShadowEffect + { + get => _settings.UseDropShadowEffect; + set + { + if (_theme.BlurEnabled && value) + { + _context.API.ShowMsgBox(_context.API.GetTranslation("shadowEffectNotAllowed")); + return; + } + + if (value) + { + _theme.AddDropShadowEffectToCurrentTheme(); + } + else + { + _theme.RemoveDropShadowEffectFromCurrentTheme(); + } + + _settings.UseDropShadowEffect = value; + } + } + + #endregion + public ThemeSelector(PluginInitContext context) { _context = context; @@ -20,52 +68,66 @@ namespace Flow.Launcher.Plugin.Sys public List Query(Query query) { - var themes = _theme.LoadAvailableThemes().Select(x => x.FileNameWithoutExtension); - - string search = query.SecondToEndSearch; - + var search = query.SecondToEndSearch; if (string.IsNullOrWhiteSpace(search)) { - return themes.Select(CreateThemeResult) + return Themes.Select(CreateThemeResult) .OrderBy(x => x.Title) .ToList(); } - return themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme))) + return Themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name))) .Where(x => x.matchResult.IsSearchPrecisionScoreMet()) .Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData)) .OrderBy(x => x.Title) .ToList(); } - private Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null); + private Result CreateThemeResult(Theme.ThemeData theme) => CreateThemeResult(theme, 0, null); - private Result CreateThemeResult(string theme, int score, IList highlightData) + private Result CreateThemeResult(Theme.ThemeData theme, int score, IList highlightData) { + string themeName = theme.Name; string title; - if (theme == _theme.CurrentTheme) + if (theme == SelectedTheme) { - title = $"{theme} ★"; + title = $"{theme.Name} ★"; // Set current theme to the top score = 2000; } else { - title = theme; + title = theme.Name; // Set them to 1000 so that they are higher than other non-theme records score = 1000; } + string description = string.Empty; + if (theme.IsDark == true) + { + description += _context.API.GetTranslation("TypeIsDarkToolTip"); + if (theme.HasBlur == true) + { + description += ""; + description += _context.API.GetTranslation("TypeHasBlurToolTip"); + } + } + else if (theme.HasBlur == true) + { + description += _context.API.GetTranslation("TypeHasBlurToolTip"); + } + return new Result { Title = title, TitleHighlightData = highlightData, + SubTitle = description, IcoPath = "Images\\theme_selector.png", Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue790"), Score = score, Action = c => { - _theme.ChangeTheme(theme); + SelectedTheme = theme; _context.API.ReQuery(); return false; }