|
1 | 1 | using System.Collections.Generic; |
2 | 2 | using System.Linq; |
3 | | -using Flow.Launcher.Core.Plugin; |
4 | 3 |
|
5 | 4 | namespace Flow.Launcher.Plugin.PluginIndicator |
6 | 5 | { |
7 | 6 | public class Main : IPlugin, IPluginI18n |
8 | 7 | { |
9 | | - private PluginInitContext context; |
| 8 | + internal PluginInitContext Context { get; private set; } |
10 | 9 |
|
11 | 10 | public List<Result> Query(Query query) |
12 | 11 | { |
| 12 | + var nonGlobalPlugins = GetNonGlobalPlugins(); |
13 | 13 | var results = |
14 | | - from keyword in PluginManager.NonGlobalPlugins.Keys |
15 | | - let plugin = PluginManager.NonGlobalPlugins[keyword].Metadata |
16 | | - let keywordSearchResult = context.API.FuzzySearch(query.Search, keyword) |
17 | | - let searchResult = keywordSearchResult.IsSearchPrecisionScoreMet() ? keywordSearchResult : context.API.FuzzySearch(query.Search, plugin.Name) |
| 14 | + from keyword in nonGlobalPlugins.Keys |
| 15 | + let plugin = nonGlobalPlugins[keyword].Metadata |
| 16 | + let keywordSearchResult = Context.API.FuzzySearch(query.Search, keyword) |
| 17 | + let searchResult = keywordSearchResult.IsSearchPrecisionScoreMet() ? keywordSearchResult : Context.API.FuzzySearch(query.Search, plugin.Name) |
18 | 18 | let score = searchResult.Score |
19 | 19 | where (searchResult.IsSearchPrecisionScoreMet() |
20 | 20 | || string.IsNullOrEmpty(query.Search)) // To list all available action keywords |
21 | 21 | && !plugin.Disabled |
22 | 22 | select new Result |
23 | 23 | { |
24 | 24 | Title = keyword, |
25 | | - SubTitle = string.Format(context.API.GetTranslation("flowlauncher_plugin_pluginindicator_result_subtitle"), plugin.Name), |
| 25 | + SubTitle = string.Format(Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_result_subtitle"), plugin.Name), |
26 | 26 | Score = score, |
27 | 27 | IcoPath = plugin.IcoPath, |
28 | 28 | AutoCompleteText = $"{keyword}{Plugin.Query.TermSeparator}", |
29 | 29 | Action = c => |
30 | 30 | { |
31 | | - context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}"); |
| 31 | + Context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}"); |
32 | 32 | return false; |
33 | 33 | } |
34 | 34 | }; |
35 | 35 | return results.ToList(); |
36 | 36 | } |
37 | 37 |
|
| 38 | + private Dictionary<string, PluginPair> GetNonGlobalPlugins() |
| 39 | + { |
| 40 | + var nonGlobalPlugins = new Dictionary<string, PluginPair>(); |
| 41 | + foreach (var plugin in Context.API.GetAllPlugins()) |
| 42 | + { |
| 43 | + foreach (var actionKeyword in plugin.Metadata.ActionKeywords) |
| 44 | + { |
| 45 | + // Skip global keywords |
| 46 | + if (actionKeyword == Plugin.Query.GlobalPluginWildcardSign) continue; |
| 47 | + |
| 48 | + // Skip dulpicated keywords |
| 49 | + if (nonGlobalPlugins.ContainsKey(actionKeyword)) continue; |
| 50 | + |
| 51 | + nonGlobalPlugins.Add(actionKeyword, plugin); |
| 52 | + } |
| 53 | + } |
| 54 | + return nonGlobalPlugins; |
| 55 | + } |
| 56 | + |
38 | 57 | public void Init(PluginInitContext context) |
39 | 58 | { |
40 | | - this.context = context; |
| 59 | + Context = context; |
41 | 60 | } |
42 | 61 |
|
43 | 62 | public string GetTranslatedPluginTitle() |
44 | 63 | { |
45 | | - return context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name"); |
| 64 | + return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name"); |
46 | 65 | } |
47 | 66 |
|
48 | 67 | public string GetTranslatedPluginDescription() |
49 | 68 | { |
50 | | - return context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description"); |
| 69 | + return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description"); |
51 | 70 | } |
52 | 71 | } |
53 | 72 | } |
0 commit comments