From 11e05f73d99a9df4ecb09daad49a4f836530a9d3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 21 Jul 2025 17:00:19 +0800 Subject: [PATCH] Add all loaded plugins --- Flow.Launcher.Core/Plugin/PluginManager.cs | 28 ++++++++++++---------- Flow.Launcher/App.xaml.cs | 4 ++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index fdd4c7fed..bce2b1fe6 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -30,7 +30,8 @@ namespace Flow.Launcher.Core.Plugin private static IPublicAPI api = null; private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService(); - private static readonly ConcurrentDictionary _allPlugins = []; + private static List _allLoadedPlugins; + private static readonly ConcurrentDictionary _allInitializedPlugins = []; private static readonly ConcurrentDictionary _globalPlugins = []; private static readonly ConcurrentDictionary _nonGlobalPlugins = []; @@ -192,20 +193,17 @@ namespace Flow.Launcher.Core.Plugin /// Load plugins from the directories specified in Directories. /// /// - /// - public static List LoadPlugins(PluginsSettings settings) + public static void LoadPlugins(PluginsSettings settings) { var metadatas = PluginConfig.Parse(Directories); Settings = settings; Settings.UpdatePluginSettings(metadatas); // Load plugins - var allPlugins = PluginsLoader.Plugins(metadatas, Settings); + _allLoadedPlugins = PluginsLoader.Plugins(metadatas, Settings); // Since dotnet plugins need to get assembly name first, we should update plugin directory after loading plugins UpdatePluginDirectory(metadatas); - - return allPlugins; } private static void UpdatePluginDirectory(List metadatas) @@ -238,14 +236,13 @@ namespace Flow.Launcher.Core.Plugin /// /// Initialize all plugins asynchronously. /// - /// List of all plugins to initialize. /// The register to register results updated event for each plugin. /// return the list of failed to init plugins or null for none - public static async Task InitializePluginsAsync(List allPlugins, IResultUpdateRegister register) + public static async Task InitializePluginsAsync(IResultUpdateRegister register) { var failedPlugins = new ConcurrentQueue(); - var initTasks = allPlugins.Select(pair => Task.Run(async () => + var initTasks = _allLoadedPlugins.Select(pair => Task.Run(async () => { try { @@ -275,7 +272,7 @@ namespace Flow.Launcher.Core.Plugin // Even if the plugin cannot be initialized, we still need to add it in all plugin list so that // we can remove the plugin from Plugin or Store page or Plugin Manager plugin. - _allPlugins.TryAdd(pair.Metadata.ID, pair); + _allInitializedPlugins.TryAdd(pair.Metadata.ID, pair); return; } @@ -348,7 +345,7 @@ namespace Flow.Launcher.Core.Plugin { _externalPreviewPlugins.Add(pair); } - _allPlugins.TryAdd(pair.Metadata.ID, pair); + _allInitializedPlugins.TryAdd(pair.Metadata.ID, pair); } #endregion @@ -519,9 +516,14 @@ namespace Flow.Launcher.Core.Plugin #region Get Plugin List + public static List GetAllLoadedPlugins() + { + return [.. _allLoadedPlugins]; + } + public static List GetAllInitializedPlugins() { - return [.. _allPlugins.Values]; + return [.. _allInitializedPlugins.Values]; } public static List GetGlobalPlugins() @@ -884,7 +886,7 @@ namespace Flow.Launcher.Core.Plugin string.Format(API.GetTranslation("failedToRemovePluginCacheMessage"), plugin.Name)); } Settings.RemovePluginSettings(plugin.ID); - _allPlugins.TryRemove(plugin.ID, out var item); + _allInitializedPlugins.TryRemove(plugin.ID, out var item); _globalPlugins.TryRemove(plugin.ID, out var item1); var keysToRemove = _nonGlobalPlugins.Where(p => p.Value.Metadata.ID == plugin.ID).Select(p => p.Key).ToList(); foreach (var key in keysToRemove) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 82f49958c..907833700 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -249,9 +249,9 @@ namespace Flow.Launcher AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings); - var allPlugins = PluginManager.LoadPlugins(_settings.PluginSettings); + PluginManager.LoadPlugins(_settings.PluginSettings); - await PluginManager.InitializePluginsAsync(allPlugins, _mainVM); + await PluginManager.InitializePluginsAsync(_mainVM); AutoPluginUpdates();