mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #456 from Flow-Launcher/fix_duplicate_query_search
fix duplicate query searches from same global action keywords
This commit is contained in:
commit
ad98e8fa4b
2 changed files with 15 additions and 20 deletions
|
|
@ -21,8 +21,8 @@ namespace Flow.Launcher.Core.Plugin
|
|||
private static IEnumerable<PluginPair> _contextMenuPlugins;
|
||||
|
||||
public static List<PluginPair> AllPlugins { get; private set; }
|
||||
public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
|
||||
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
|
||||
public static readonly HashSet<PluginPair> GlobalPlugins = new();
|
||||
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new ();
|
||||
|
||||
public static IPublicAPI API { private set; get; }
|
||||
|
||||
|
|
@ -118,7 +118,9 @@ namespace Flow.Launcher.Core.Plugin
|
|||
_contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
||||
foreach (var plugin in AllPlugins)
|
||||
{
|
||||
foreach (var actionKeyword in plugin.Metadata.ActionKeywords)
|
||||
// set distinct on each plugin's action keywords helps only firing global(*) and action keywords once where a plugin
|
||||
// has multiple global and action keywords because we will only add them here once.
|
||||
foreach (var actionKeyword in plugin.Metadata.ActionKeywords.Distinct())
|
||||
{
|
||||
switch (actionKeyword)
|
||||
{
|
||||
|
|
@ -141,7 +143,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
}
|
||||
|
||||
public static List<PluginPair> ValidPluginsForQuery(Query query)
|
||||
public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
|
||||
{
|
||||
if (NonGlobalPlugins.ContainsKey(query.ActionKeyword))
|
||||
{
|
||||
|
|
@ -283,9 +285,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
if (oldActionkeyword == Query.GlobalPluginWildcardSign
|
||||
&& // Plugins may have multiple ActionKeywords that are global, eg. WebSearch
|
||||
plugin.Metadata.ActionKeywords
|
||||
.Where(x => x == Query.GlobalPluginWildcardSign)
|
||||
.ToList()
|
||||
.Count == 1)
|
||||
.Count(x => x == Query.GlobalPluginWildcardSign) == 1)
|
||||
{
|
||||
GlobalPlugins.Remove(plugin);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -494,21 +494,16 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}, currentCancellationToken);
|
||||
|
||||
Task[] tasks = new Task[plugins.Count];
|
||||
// plugins is ICollection, meaning LINQ will get the Count and preallocate Array
|
||||
|
||||
Task[] tasks = plugins.Select(plugin => plugin.Metadata.Disabled switch
|
||||
{
|
||||
false => QueryTask(plugin),
|
||||
true => Task.CompletedTask
|
||||
}).ToArray();
|
||||
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < plugins.Count; i++)
|
||||
{
|
||||
if (!plugins[i].Metadata.Disabled)
|
||||
{
|
||||
tasks[i] = QueryTask(plugins[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
tasks[i] = Task.CompletedTask; // Avoid Null
|
||||
}
|
||||
}
|
||||
|
||||
// Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue