-
-
Notifications
You must be signed in to change notification settings - Fork 620
Expand file tree
/
Copy pathMain.cs
More file actions
84 lines (73 loc) · 3.01 KB
/
Copy pathMain.cs
File metadata and controls
84 lines (73 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System.Collections.Generic;
using System.Linq;
namespace Flow.Launcher.Plugin.PluginIndicator
{
public class Main : IPlugin, IPluginI18n, IHomeQuery
{
internal static PluginInitContext Context { get; private set; }
public void Init(PluginInitContext context)
{
Context = context;
}
public List<Result> Query(Query query)
{
return QueryResults(query);
}
private static List<Result> QueryResults(Query query = null)
{
var nonGlobalPlugins = GetNonGlobalPlugins();
var querySearch = query?.Search ?? string.Empty;
var results =
from keyword in nonGlobalPlugins.Keys
let plugin = nonGlobalPlugins[keyword].Metadata
let keywordSearchResult = Context.API.FuzzySearch(querySearch, keyword)
let searchResult = keywordSearchResult.IsSearchPrecisionScoreMet() ? keywordSearchResult : Context.API.FuzzySearch(querySearch, plugin.Name)
let score = searchResult.Score
where (searchResult.IsSearchPrecisionScoreMet()
|| string.IsNullOrEmpty(querySearch)) // To list all available action keywords
&& !plugin.Disabled
select new Result
{
Title = keyword,
SubTitle = Localize.flowlauncher_plugin_pluginindicator_result_subtitle(plugin.Name),
Score = score,
IcoPath = plugin.IcoPath,
AutoCompleteText = $"{keyword}{Plugin.Query.TermSeparator}",
Action = c =>
{
Context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}");
return false;
}
};
return [.. results];
}
private static Dictionary<string, PluginPair> GetNonGlobalPlugins()
{
var nonGlobalPlugins = new Dictionary<string, PluginPair>();
foreach (var plugin in Context.API.GetAllPlugins())
{
foreach (var actionKeyword in plugin.Metadata.ActionKeywords)
{
// Skip global keywords
if (actionKeyword == Plugin.Query.GlobalPluginWildcardSign) continue;
// Skip dulpicated keywords
if (nonGlobalPlugins.ContainsKey(actionKeyword)) continue;
nonGlobalPlugins.Add(actionKeyword, plugin);
}
}
return nonGlobalPlugins;
}
public string GetTranslatedPluginTitle()
{
return Localize.flowlauncher_plugin_pluginindicator_plugin_name();
}
public string GetTranslatedPluginDescription()
{
return Localize.flowlauncher_plugin_pluginindicator_plugin_description();
}
public List<Result> HomeQuery()
{
return QueryResults();
}
}
}