From bad304b38f25aeddbb20a2c57a8d13704e99230f Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Wed, 12 Mar 2025 21:50:39 +0800 Subject: [PATCH] Query themes every time --- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 8 +-- .../Flow.Launcher.Plugin.Sys/ThemeSelector.cs | 54 ++----------------- 2 files changed, 5 insertions(+), 57 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index c41e159dc..28747cc7c 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -7,7 +7,6 @@ using System.Windows; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; -using Flow.Launcher.Plugin.SharedCommands; using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.Security; @@ -17,7 +16,7 @@ using Control = System.Windows.Controls.Control; namespace Flow.Launcher.Plugin.Sys { - public class Main : IPlugin, ISettingProvider, IPluginI18n, IDisposable + public class Main : IPlugin, ISettingProvider, IPluginI18n { private PluginInitContext context; private ThemeSelector themeSelector; @@ -486,10 +485,5 @@ namespace Flow.Launcher.Plugin.Sys { return context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description"); } - - public void Dispose() - { - themeSelector.Dispose(); - } } } diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index 658c3b0a8..bbc45c180 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -1,38 +1,26 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Core.Resource; namespace Flow.Launcher.Plugin.Sys { - public class ThemeSelector : IDisposable + public class ThemeSelector { public const string Keyword = "fltheme"; private readonly Theme _theme; private readonly PluginInitContext _context; - private IEnumerable themes; - public ThemeSelector(PluginInitContext context) { _context = context; _theme = Ioc.Default.GetRequiredService(); - context.API.VisibilityChanged += OnVisibilityChanged; - } - - ~ThemeSelector() - { - Dispose(false); } public List Query(Query query) { - if (query.IsReQuery) - { - LoadThemes(); - } + var themes = _theme.LoadAvailableThemes().Select(x => x.FileNameWithoutExtension); string search = query.SecondToEndSearch; @@ -50,17 +38,6 @@ namespace Flow.Launcher.Plugin.Sys .ToList(); } - private void OnVisibilityChanged(object sender, VisibilityChangedEventArgs args) - { - if (args.IsVisible && !_context.CurrentPluginMetadata.Disabled) - { - LoadThemes(); - } - } - - private void LoadThemes() - => themes = _theme.LoadAvailableThemes().Select(x => x.FileNameWithoutExtension); - private Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null); private Result CreateThemeResult(string theme, int score, IList highlightData) @@ -69,6 +46,7 @@ namespace Flow.Launcher.Plugin.Sys if (theme == _theme.CurrentTheme) { title = $"{theme} ★"; + // Set current theme to the top score = 2000; } else @@ -92,29 +70,5 @@ namespace Flow.Launcher.Plugin.Sys } }; } - - private bool disposed; - protected virtual void Dispose(bool disposing) - { - if (!disposed) - { - if (disposing) - { - // Dispose managed resources - if (_context?.API != null) - { - _context.API.VisibilityChanged -= OnVisibilityChanged; - } - } - // Free unmanaged resources - disposed = true; - } - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } } }