Skip to content

Commit 4ad75f2

Browse files
committed
Do not use task to run plugin init event
1 parent 57f20ae commit 4ad75f2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ public static async Task InitializePluginsAsync()
165165
{
166166
var failedPlugins = new ConcurrentQueue<PluginPair>();
167167

168-
var InitTasks = AllPlugins.Select(pair => Task.Run(async delegate
168+
// Some plugins should not be initialized in task, so we cannot use Task.WhenAll here
169+
foreach (var pair in AllPlugins)
169170
{
170171
try
171172
{
@@ -182,9 +183,7 @@ public static async Task InitializePluginsAsync()
182183
pair.Metadata.Disabled = true;
183184
failedPlugins.Enqueue(pair);
184185
}
185-
}));
186-
187-
await Task.WhenAll(InitTasks);
186+
}
188187

189188
_contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
190189
foreach (var plugin in AllPlugins)

Flow.Launcher.Plugin/Interfaces/IPlugin.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ public interface IPlugin : IAsyncPlugin
3030
/// <param name="context"></param>
3131
void Init(PluginInitContext context);
3232

33-
Task IAsyncPlugin.InitAsync(PluginInitContext context) => Task.Run(() => Init(context));
33+
async Task IAsyncPlugin.InitAsync(PluginInitContext context)
34+
{
35+
// Some plugins should not be initialized in task
36+
Init(context);
37+
await Task.CompletedTask;
38+
}
3439

3540
Task<List<Result>> IAsyncPlugin.QueryAsync(Query query, CancellationToken token) => Task.Run(() => Query(query));
3641
}

0 commit comments

Comments
 (0)