Skip to content

Commit ad98e8f

Browse files
authored
Merge pull request #456 from Flow-Launcher/fix_duplicate_query_search
fix duplicate query searches from same global action keywords
2 parents 08d428e + efc45c7 commit ad98e8f

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public static class PluginManager
2121
private static IEnumerable<PluginPair> _contextMenuPlugins;
2222

2323
public static List<PluginPair> AllPlugins { get; private set; }
24-
public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
25-
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
24+
public static readonly HashSet<PluginPair> GlobalPlugins = new();
25+
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new ();
2626

2727
public static IPublicAPI API { private set; get; }
2828

@@ -118,7 +118,9 @@ public static async Task InitializePlugins(IPublicAPI api)
118118
_contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
119119
foreach (var plugin in AllPlugins)
120120
{
121-
foreach (var actionKeyword in plugin.Metadata.ActionKeywords)
121+
// set distinct on each plugin's action keywords helps only firing global(*) and action keywords once where a plugin
122+
// has multiple global and action keywords because we will only add them here once.
123+
foreach (var actionKeyword in plugin.Metadata.ActionKeywords.Distinct())
122124
{
123125
switch (actionKeyword)
124126
{
@@ -141,7 +143,7 @@ public static async Task InitializePlugins(IPublicAPI api)
141143
}
142144
}
143145

144-
public static List<PluginPair> ValidPluginsForQuery(Query query)
146+
public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
145147
{
146148
if (NonGlobalPlugins.ContainsKey(query.ActionKeyword))
147149
{
@@ -283,9 +285,7 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
283285
if (oldActionkeyword == Query.GlobalPluginWildcardSign
284286
&& // Plugins may have multiple ActionKeywords that are global, eg. WebSearch
285287
plugin.Metadata.ActionKeywords
286-
.Where(x => x == Query.GlobalPluginWildcardSign)
287-
.ToList()
288-
.Count == 1)
288+
.Count(x => x == Query.GlobalPluginWildcardSign) == 1)
289289
{
290290
GlobalPlugins.Remove(plugin);
291291
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -494,21 +494,16 @@ private void QueryResults()
494494
}
495495
}, currentCancellationToken);
496496

497-
Task[] tasks = new Task[plugins.Count];
498-
try
497+
// plugins is ICollection, meaning LINQ will get the Count and preallocate Array
498+
499+
Task[] tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch
499500
{
500-
for (var i = 0; i < plugins.Count; i++)
501-
{
502-
if (!plugins[i].Metadata.Disabled)
503-
{
504-
tasks[i] = QueryTask(plugins[i]);
505-
}
506-
else
507-
{
508-
tasks[i] = Task.CompletedTask; // Avoid Null
509-
}
510-
}
501+
false => QueryTask(plugin),
502+
true => Task.CompletedTask
503+
}).ToArray();
511504

505+
try
506+
{
512507
// Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
513508
await Task.WhenAll(tasks);
514509
}

0 commit comments

Comments
 (0)