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