Skip to content

Commit 33c3674

Browse files
committed
Reload IAsyncReloadable concurrently
1 parent bc0863c commit 33c3674

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static class PluginManager
3333
/// <summary>
3434
/// Directories that will hold Flow Launcher plugin directory
3535
/// </summary>
36-
private static readonly string[] Directories = {Constant.PreinstalledDirectory, DataLocation.PluginsDirectory};
36+
private static readonly string[] Directories = { Constant.PreinstalledDirectory, DataLocation.PluginsDirectory };
3737

3838
private static void DeletePythonBinding()
3939
{
@@ -55,18 +55,21 @@ public static void Save()
5555

5656
public static async Task ReloadData()
5757
{
58-
foreach(var plugin in AllPlugins)
58+
await Task.WhenAll(AllPlugins.Select(plugin =>
5959
{
60-
switch (plugin.Plugin)
6160
{
62-
case IReloadable p:
63-
p.ReloadData();
64-
break;
65-
case IAsyncReloadable p:
66-
await p.ReloadDataAsync();
67-
break;
61+
switch (plugin)
62+
{
63+
case IReloadable p:
64+
p.ReloadData(); // Sync reload means low time consuming
65+
return Task.CompletedTask;
66+
case IAsyncReloadable p:
67+
return p.ReloadDataAsync();
68+
default:
69+
throw new ArgumentOutOfRangeException();
70+
}
6871
}
69-
}
72+
}));
7073
}
7174

7275
static PluginManager()
@@ -142,7 +145,7 @@ await plugin.InitAsync(new PluginInitContext
142145
catch (Exception e)
143146
{
144147
Log.Exception(nameof(PluginManager), $"Fail to Init plugin: {pair.Metadata.Name}", e);
145-
pair.Metadata.Disabled = true;
148+
pair.Metadata.Disabled = true;
146149
failedPlugins.Enqueue(pair);
147150
}
148151
}));
@@ -180,7 +183,7 @@ public static List<PluginPair> ValidPluginsForQuery(Query query)
180183
if (NonGlobalPlugins.ContainsKey(query.ActionKeyword))
181184
{
182185
var plugin = NonGlobalPlugins[query.ActionKeyword];
183-
return new List<PluginPair> {plugin};
186+
return new List<PluginPair> { plugin };
184187
}
185188
else
186189
{
@@ -262,7 +265,7 @@ public static List<Result> GetContextMenusForPlugin(Result result)
262265
var pluginPair = _contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
263266
if (pluginPair != null)
264267
{
265-
var plugin = (IContextMenu) pluginPair.Plugin;
268+
var plugin = (IContextMenu)pluginPair.Plugin;
266269

267270
try
268271
{
@@ -326,10 +329,10 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
326329
{
327330
GlobalPlugins.Remove(plugin);
328331
}
329-
332+
330333
if (oldActionkeyword != Query.GlobalPluginWildcardSign)
331334
NonGlobalPlugins.Remove(oldActionkeyword);
332-
335+
333336

334337
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
335338
}

0 commit comments

Comments
 (0)