From 4ad75f21dc207d62c8937b2af7457a432deae407 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 3 Mar 2025 21:03:08 +0800 Subject: [PATCH] Do not use task to run plugin init event --- Flow.Launcher.Core/Plugin/PluginManager.cs | 7 +++---- Flow.Launcher.Plugin/Interfaces/IPlugin.cs | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 09711051e24..f1dfef58772 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -165,7 +165,8 @@ public static async Task InitializePluginsAsync() { var failedPlugins = new ConcurrentQueue(); - var InitTasks = AllPlugins.Select(pair => Task.Run(async delegate + // Some plugins should not be initialized in task, so we cannot use Task.WhenAll here + foreach (var pair in AllPlugins) { try { @@ -182,9 +183,7 @@ public static async Task InitializePluginsAsync() pair.Metadata.Disabled = true; failedPlugins.Enqueue(pair); } - })); - - await Task.WhenAll(InitTasks); + } _contextMenuPlugins = GetPluginsForInterface(); foreach (var plugin in AllPlugins) diff --git a/Flow.Launcher.Plugin/Interfaces/IPlugin.cs b/Flow.Launcher.Plugin/Interfaces/IPlugin.cs index bac93d090cd..ee0d0940c4a 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPlugin.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPlugin.cs @@ -30,7 +30,12 @@ public interface IPlugin : IAsyncPlugin /// void Init(PluginInitContext context); - Task IAsyncPlugin.InitAsync(PluginInitContext context) => Task.Run(() => Init(context)); + async Task IAsyncPlugin.InitAsync(PluginInitContext context) + { + // Some plugins should not be initialized in task + Init(context); + await Task.CompletedTask; + } Task> IAsyncPlugin.QueryAsync(Query query, CancellationToken token) => Task.Run(() => Query(query)); }