From 358b1fd7c875e4e4863227d53ee977872a9bd703 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 4 Apr 2025 20:10:39 +0800 Subject: [PATCH 01/13] Move theme data and functions into api --- Flow.Launcher.Core/Resource/Theme.cs | 31 ++++---- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 19 +++++ Flow.Launcher.Plugin/ThemeData.cs | 71 +++++++++++++++++++ Flow.Launcher/PublicAPIInstance.cs | 13 ++++ 4 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 Flow.Launcher.Plugin/ThemeData.cs diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index e5980b62fa3..4cf9ce7a714 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -81,11 +81,6 @@ public Theme(IPublicAPI publicAPI, Settings settings) #region Theme Resources - public string GetCurrentTheme() - { - return _settings.Theme; - } - private void MakeSureThemeDirectoriesExist() { foreach (var dir in _themeDirectories.Where(dir => !Directory.Exists(dir))) @@ -127,7 +122,7 @@ public void UpdateFonts() try { // Load a ResourceDictionary for the specified theme. - var themeName = GetCurrentTheme(); + var themeName = _settings.Theme; var dict = GetThemeResourceDictionary(themeName); // Apply font settings to the theme resource. @@ -330,7 +325,7 @@ private ResourceDictionary GetResourceDictionary(string theme) private ResourceDictionary GetCurrentResourceDictionary() { - return GetResourceDictionary(GetCurrentTheme()); + return GetResourceDictionary(_settings.Theme); } private ThemeData GetThemeDataFromPath(string path) @@ -383,9 +378,15 @@ private string GetThemePath(string themeName) #endregion - #region Load & Change + #region Get & Change Theme + + public ThemeData GetCurrentTheme() + { + var themes = GetAvailableThemes(); + return themes.FirstOrDefault(t => t.FileNameWithoutExtension == _settings.Theme) ?? themes.FirstOrDefault(); + } - public List LoadAvailableThemes() + public List GetAvailableThemes() { List themes = new List(); foreach (var themeDirectory in _themeDirectories) @@ -403,7 +404,7 @@ public List LoadAvailableThemes() public bool ChangeTheme(string theme = null) { if (string.IsNullOrEmpty(theme)) - theme = GetCurrentTheme(); + theme = _settings.Theme; string path = GetThemePath(theme); try @@ -591,7 +592,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => { AutoDropShadow(useDropShadowEffect); } - SetBlurForWindow(GetCurrentTheme(), backdropType); + SetBlurForWindow(_settings.Theme, backdropType); if (!BlurEnabled) { @@ -610,7 +611,7 @@ await Application.Current.Dispatcher.InvokeAsync(() => // Get the actual backdrop type and drop shadow effect settings var (backdropType, _) = GetActualValue(); - SetBlurForWindow(GetCurrentTheme(), backdropType); + SetBlurForWindow(_settings.Theme, backdropType); }, DispatcherPriority.Render); } @@ -898,11 +899,5 @@ private static bool IsBlurTheme() } #endregion - - #region Classes - - public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? HasBlur = null); - - #endregion } } diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index f178ebb90d4..bfcc2f9e060 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -344,5 +344,24 @@ public interface IPublicAPI /// Stop the loading bar in main window /// public void StopLoadingBar(); + + /// + /// Get all available themes + /// + /// + public List GetAvailableThemes(); + + /// + /// Get the current theme + /// + /// + public ThemeData GetCurrentTheme(); + + /// + /// Set the current theme + /// + /// + /// + public void SetCurrentTheme(ThemeData theme); } } diff --git a/Flow.Launcher.Plugin/ThemeData.cs b/Flow.Launcher.Plugin/ThemeData.cs new file mode 100644 index 00000000000..d4a69ef09c5 --- /dev/null +++ b/Flow.Launcher.Plugin/ThemeData.cs @@ -0,0 +1,71 @@ +namespace Flow.Launcher.Plugin; + +/// +/// Theme data model +/// +public class ThemeData +{ + /// + /// Theme file name without extension + /// + public string FileNameWithoutExtension { get; private init; } + + /// + /// Theme name + /// + public string Name { get; private init; } + + /// + /// Theme file path + /// + public bool? IsDark { get; private init; } + + /// + /// Theme file path + /// + public bool? HasBlur { get; private init; } + + /// + /// Theme data constructor + /// + public ThemeData(string fileNameWithoutExtension, string name, bool? isDark = null, bool? hasBlur = null) + { + FileNameWithoutExtension = fileNameWithoutExtension; + Name = name; + IsDark = isDark; + HasBlur = hasBlur; + } + + /// + public static bool operator ==(ThemeData left, ThemeData right) + { + return left.Equals(right); + } + + /// + public static bool operator !=(ThemeData left, ThemeData right) + { + return !(left == right); + } + + /// + public override bool Equals(object obj) + { + if (obj is not ThemeData other) + return false; + return FileNameWithoutExtension == other.FileNameWithoutExtension && + Name == other.Name; + } + + /// + public override int GetHashCode() + { + return Name?.GetHashCode() ?? 0; + } + + /// + public override string ToString() + { + return Name; + } +} diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index d88eeb7c9e3..96ccb55c44c 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -37,6 +37,9 @@ public class PublicAPIInstance : IPublicAPI private readonly Internationalization _translater; private readonly MainViewModel _mainVM; + private Theme _theme; + private Theme Theme => _theme ??= Ioc.Default.GetRequiredService(); + private readonly object _saveSettingsLock = new(); #region Constructor @@ -354,6 +357,16 @@ public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", M public Task ShowProgressBoxAsync(string caption, Func, Task> reportProgressAsync, Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress); + public List GetAvailableThemes() => Theme.GetAvailableThemes(); + + public ThemeData GetCurrentTheme() => Theme.GetCurrentTheme(); + + public void SetCurrentTheme(ThemeData theme) + { + Theme.ChangeTheme(theme.FileNameWithoutExtension); + _ = _theme.RefreshFrameAsync(); + } + #endregion #region Private Methods From 9b9704e938f1e74584c8bc7688bc333387700c6b Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 4 Apr 2025 20:11:01 +0800 Subject: [PATCH 02/13] Improve settings panel theme page & theme selector --- .../ViewModels/SettingsPaneThemeViewModel.cs | 14 +++--- .../Flow.Launcher.Plugin.Sys/ThemeSelector.cs | 47 +++++-------------- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 6e2488fe1d1..58cf3a314b5 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -28,25 +28,23 @@ public partial class SettingsPaneThemeViewModel : BaseModel public static string LinkHowToCreateTheme => @"https://www.flowlauncher.com/theme-builder/"; public static string LinkThemeGallery => "https://github.com/Flow-Launcher/Flow.Launcher/discussions/1438"; - private List _themes; - public List Themes => _themes ??= _theme.LoadAvailableThemes(); + private List _themes; + public List Themes => _themes ??= App.API.GetAvailableThemes(); - private Theme.ThemeData _selectedTheme; - public Theme.ThemeData SelectedTheme + private ThemeData _selectedTheme; + public ThemeData SelectedTheme { - get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == _theme.GetCurrentTheme()); + get => _selectedTheme ??= Themes.Find(v => v == App.API.GetCurrentTheme()); set { _selectedTheme = value; - _theme.ChangeTheme(value.FileNameWithoutExtension); + App.API.SetCurrentTheme(value); // Update UI state OnPropertyChanged(nameof(BackdropType)); OnPropertyChanged(nameof(IsBackdropEnabled)); OnPropertyChanged(nameof(IsDropShadowEnabled)); OnPropertyChanged(nameof(DropShadowEffect)); - - _ = _theme.RefreshFrameAsync(); } } diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index 31faeba5231..84bfa218e4b 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; using System.Linq; -using CommunityToolkit.Mvvm.DependencyInjection; -using Flow.Launcher.Core.Resource; namespace Flow.Launcher.Plugin.Sys { @@ -11,32 +9,6 @@ public class ThemeSelector private readonly PluginInitContext _context; - // Do not initialize it in the constructor, because it will cause null reference in - // var dicts = Application.Current.Resources.MergedDictionaries; line of Theme - private Theme theme = null; - private Theme Theme => theme ??= Ioc.Default.GetRequiredService(); - - #region Theme Selection - - // Theme select codes simplified from SettingsPaneThemeViewModel.cs - - private Theme.ThemeData _selectedTheme; - public Theme.ThemeData SelectedTheme - { - get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == Theme.GetCurrentTheme()); - set - { - _selectedTheme = value; - Theme.ChangeTheme(value.FileNameWithoutExtension); - - _ = Theme.RefreshFrameAsync(); - } - } - - private List Themes => Theme.LoadAvailableThemes(); - - #endregion - public ThemeSelector(PluginInitContext context) { _context = context; @@ -44,28 +16,31 @@ public ThemeSelector(PluginInitContext context) public List Query(Query query) { + var themes = _context.API.GetAvailableThemes(); + var selectedTheme = _context.API.GetCurrentTheme(); + var search = query.SecondToEndSearch; if (string.IsNullOrWhiteSpace(search)) { - return Themes.Select(CreateThemeResult) + return themes.Select(x => CreateThemeResult(x, selectedTheme)) .OrderBy(x => x.Title) .ToList(); } - return Themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name))) + 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)) + .Select(x => CreateThemeResult(x.theme, selectedTheme, x.matchResult.Score, x.matchResult.MatchData)) .OrderBy(x => x.Title) .ToList(); } - private Result CreateThemeResult(Theme.ThemeData theme) => CreateThemeResult(theme, 0, null); + private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme) => CreateThemeResult(theme, selectedTheme, 0, null); - private Result CreateThemeResult(Theme.ThemeData theme, int score, IList highlightData) + private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int score, IList highlightData) { - string themeName = theme.Name; + var themeName = theme.FileNameWithoutExtension; string title; - if (theme == SelectedTheme) + if (theme == selectedTheme) { title = $"{theme.Name} ★"; // Set current theme to the top @@ -101,7 +76,7 @@ private Result CreateThemeResult(Theme.ThemeData theme, int score, IList hi Score = score, Action = c => { - SelectedTheme = theme; + _context.API.SetCurrentTheme(theme); _context.API.ReQuery(); return false; } From 1611ad37f37fde5ac054529cfa3a136e28fa3168 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 4 Apr 2025 20:15:47 +0800 Subject: [PATCH 03/13] Fix ThemeData hashcode issue --- Flow.Launcher.Plugin/ThemeData.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Plugin/ThemeData.cs b/Flow.Launcher.Plugin/ThemeData.cs index d4a69ef09c5..6cbd0fe740b 100644 --- a/Flow.Launcher.Plugin/ThemeData.cs +++ b/Flow.Launcher.Plugin/ThemeData.cs @@ -1,4 +1,6 @@ -namespace Flow.Launcher.Plugin; +using System; + +namespace Flow.Launcher.Plugin; /// /// Theme data model @@ -60,7 +62,7 @@ public override bool Equals(object obj) /// public override int GetHashCode() { - return Name?.GetHashCode() ?? 0; + return HashCode.Combine(FileNameWithoutExtension, Name); } /// From 514fa0037a0f0ad6b78ad6ae17d943764cf696c7 Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Fri, 4 Apr 2025 20:23:07 +0800 Subject: [PATCH 04/13] Improve documents Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Flow.Launcher.Plugin/ThemeData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin/ThemeData.cs b/Flow.Launcher.Plugin/ThemeData.cs index 6cbd0fe740b..90a45182c8f 100644 --- a/Flow.Launcher.Plugin/ThemeData.cs +++ b/Flow.Launcher.Plugin/ThemeData.cs @@ -23,7 +23,7 @@ public class ThemeData public bool? IsDark { get; private init; } /// - /// Theme file path + /// Indicates whether the theme supports blur effects /// public bool? HasBlur { get; private init; } From 28d92c789f181acb2060f7ff0b1c9f226bdb4905 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 4 Apr 2025 20:23:36 +0800 Subject: [PATCH 05/13] Improve documents --- Flow.Launcher.Plugin/ThemeData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin/ThemeData.cs b/Flow.Launcher.Plugin/ThemeData.cs index 90a45182c8f..1888be65e1d 100644 --- a/Flow.Launcher.Plugin/ThemeData.cs +++ b/Flow.Launcher.Plugin/ThemeData.cs @@ -18,7 +18,7 @@ public class ThemeData public string Name { get; private init; } /// - /// Theme file path + /// Indicates whether the theme supports dark mode /// public bool? IsDark { get; private init; } From 2e885ea5ccec4a42de61e1d1fe6ced1e319656ce Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 4 Apr 2025 20:45:24 +0800 Subject: [PATCH 06/13] Remove useless variable --- Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index 84bfa218e4b..4b99efe3b1a 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -38,7 +38,6 @@ public List Query(Query query) private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int score, IList highlightData) { - var themeName = theme.FileNameWithoutExtension; string title; if (theme == selectedTheme) { From ecd019dd6b0c286a6cf223cf598bc1fc57dd4279 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 8 Apr 2025 15:56:54 +0800 Subject: [PATCH 07/13] Move ThemeData class to SharedModels --- Flow.Launcher.Core/Resource/Theme.cs | 1 + Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 6 +++--- Flow.Launcher.Plugin/{ => SharedModels}/ThemeData.cs | 2 +- .../SettingPages/ViewModels/SettingsPaneThemeViewModel.cs | 1 + Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs | 1 + 5 files changed, 7 insertions(+), 4 deletions(-) rename Flow.Launcher.Plugin/{ => SharedModels}/ThemeData.cs (97%) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 4cf9ce7a714..f3eba7ba7fd 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -16,6 +16,7 @@ using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; +using Flow.Launcher.Plugin.SharedModels; using Microsoft.Win32; namespace Flow.Launcher.Core.Resource diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index 64bdcec3474..1090a3a1e9f 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -1,6 +1,4 @@ -using Flow.Launcher.Plugin.SharedModels; -using JetBrains.Annotations; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; @@ -8,6 +6,8 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; +using Flow.Launcher.Plugin.SharedModels; +using JetBrains.Annotations; namespace Flow.Launcher.Plugin { diff --git a/Flow.Launcher.Plugin/ThemeData.cs b/Flow.Launcher.Plugin/SharedModels/ThemeData.cs similarity index 97% rename from Flow.Launcher.Plugin/ThemeData.cs rename to Flow.Launcher.Plugin/SharedModels/ThemeData.cs index 1888be65e1d..6a5e54f5508 100644 --- a/Flow.Launcher.Plugin/ThemeData.cs +++ b/Flow.Launcher.Plugin/SharedModels/ThemeData.cs @@ -1,6 +1,6 @@ using System; -namespace Flow.Launcher.Plugin; +namespace Flow.Launcher.Plugin.SharedModels; /// /// Theme data model diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 58cf3a314b5..f78704ef2d5 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -12,6 +12,7 @@ using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; +using Flow.Launcher.Plugin.SharedModels; using Flow.Launcher.ViewModel; using ModernWpf; using ThemeManagerForColorSchemeSwitch = ModernWpf.ThemeManager; diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index 4b99efe3b1a..feacc3f9921 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using Flow.Launcher.Plugin.SharedModels; namespace Flow.Launcher.Plugin.Sys { From 6c458828bc9d24a58de29240f1417c253c64a7d6 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 8 Apr 2025 16:01:46 +0800 Subject: [PATCH 08/13] Fix possible NullReferenceException --- Flow.Launcher.Plugin/SharedModels/ThemeData.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Flow.Launcher.Plugin/SharedModels/ThemeData.cs b/Flow.Launcher.Plugin/SharedModels/ThemeData.cs index 6a5e54f5508..322985f3a9b 100644 --- a/Flow.Launcher.Plugin/SharedModels/ThemeData.cs +++ b/Flow.Launcher.Plugin/SharedModels/ThemeData.cs @@ -41,12 +41,16 @@ public ThemeData(string fileNameWithoutExtension, string name, bool? isDark = nu /// public static bool operator ==(ThemeData left, ThemeData right) { + if (left is null && right is null) + return true; return left.Equals(right); } /// public static bool operator !=(ThemeData left, ThemeData right) { + if (left is null && right is null) + return false; return !(left == right); } From 537c03f2d751345176bbeacf1d58a657da3aef31 Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Tue, 8 Apr 2025 16:13:58 +0800 Subject: [PATCH 09/13] Fix null check issue Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- Flow.Launcher.Plugin/SharedModels/ThemeData.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Flow.Launcher.Plugin/SharedModels/ThemeData.cs b/Flow.Launcher.Plugin/SharedModels/ThemeData.cs index 322985f3a9b..093e1ee8e55 100644 --- a/Flow.Launcher.Plugin/SharedModels/ThemeData.cs +++ b/Flow.Launcher.Plugin/SharedModels/ThemeData.cs @@ -43,6 +43,8 @@ public ThemeData(string fileNameWithoutExtension, string name, bool? isDark = nu { if (left is null && right is null) return true; + if (left is null || right is null) + return false; return left.Equals(right); } From b3aa89773ce1fdfadc9dfd06b13acc596d504265 Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Tue, 8 Apr 2025 16:14:17 +0800 Subject: [PATCH 10/13] Use == for != operator Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- Flow.Launcher.Plugin/SharedModels/ThemeData.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedModels/ThemeData.cs b/Flow.Launcher.Plugin/SharedModels/ThemeData.cs index 093e1ee8e55..cb389c21fbc 100644 --- a/Flow.Launcher.Plugin/SharedModels/ThemeData.cs +++ b/Flow.Launcher.Plugin/SharedModels/ThemeData.cs @@ -51,8 +51,6 @@ public ThemeData(string fileNameWithoutExtension, string name, bool? isDark = nu /// public static bool operator !=(ThemeData left, ThemeData right) { - if (left is null && right is null) - return false; return !(left == right); } From a2d99573855b145a4ac68f270494c05f07ea06a6 Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Tue, 8 Apr 2025 16:20:11 +0800 Subject: [PATCH 11/13] Log warning if cannot find matched theme Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Flow.Launcher.Core/Resource/Theme.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index f3eba7ba7fd..d7c6193302e 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -384,7 +384,12 @@ private string GetThemePath(string themeName) public ThemeData GetCurrentTheme() { var themes = GetAvailableThemes(); - return themes.FirstOrDefault(t => t.FileNameWithoutExtension == _settings.Theme) ?? themes.FirstOrDefault(); + var matchingTheme = themes.FirstOrDefault(t => t.FileNameWithoutExtension == _settings.Theme); + if (matchingTheme == null) + { + Log.Warn($"No matching theme found for '{_settings.Theme}'. Falling back to the first available theme."); + } + return matchingTheme ?? themes.FirstOrDefault(); } public List GetAvailableThemes() From dd210ad41968a1e9112fb6b364a08093534ae136 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 8 Apr 2025 16:41:06 +0800 Subject: [PATCH 12/13] Remove RefreshFrameAsync since ChangeTheme calls this function --- Flow.Launcher.Core/Resource/Theme.cs | 2 +- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 6 ++++-- Flow.Launcher/PublicAPIInstance.cs | 5 +---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index d7c6193302e..59e76e2d2e9 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -433,7 +433,7 @@ public bool ChangeTheme(string theme = null) BlurEnabled = IsBlurTheme(); - // Can only apply blur but here also apply drop shadow effect to avoid possible drop shadow effect issues + // Apply blur and drop shadow effect so that we do not need to call it again _ = RefreshFrameAsync(); return true; diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index 056c4a437b0..7701fcdd05a 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -367,8 +367,10 @@ public interface IPublicAPI /// Set the current theme /// /// - /// - public void SetCurrentTheme(ThemeData theme); + /// + /// True if the theme is set successfully, false otherwise. + /// + public bool SetCurrentTheme(ThemeData theme); /// Load image from path. Support local, remote and data:image url. /// If image path is missing, it will return a missing icon. diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index b19b21db12c..8cce460d7e0 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -377,11 +377,8 @@ public Task ShowProgressBoxAsync(string caption, Func, Task> repo public ThemeData GetCurrentTheme() => Theme.GetCurrentTheme(); - public void SetCurrentTheme(ThemeData theme) - { + public bool SetCurrentTheme(ThemeData theme) => Theme.ChangeTheme(theme.FileNameWithoutExtension); - _ = _theme.RefreshFrameAsync(); - } public ValueTask LoadImageAsync(string path, bool loadFullImage = false, bool cacheImage = true) => ImageLoader.LoadAsync(path, loadFullImage, cacheImage); From a3c7be95597f8c0765f0e62749b7f263749e78cd Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 8 Apr 2025 16:49:29 +0800 Subject: [PATCH 13/13] Handle results from SetCurrentTheme --- Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index feacc3f9921..f8aeaeafdff 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -76,8 +76,10 @@ private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int s Score = score, Action = c => { - _context.API.SetCurrentTheme(theme); - _context.API.ReQuery(); + if (_context.API.SetCurrentTheme(theme)) + { + _context.API.ReQuery(); + } return false; } };