Skip to content

Commit 6b5e20b

Browse files
committed
Improve code quality
1 parent 62abf67 commit 6b5e20b

File tree

1 file changed

+62
-63
lines changed
  • Plugins/Flow.Launcher.Plugin.PluginIndicator

1 file changed

+62
-63
lines changed
Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,83 @@
11
using System.Collections.Generic;
22
using System.Linq;
33

4-
namespace Flow.Launcher.Plugin.PluginIndicator
4+
namespace Flow.Launcher.Plugin.PluginIndicator;
5+
6+
public class Main : IPlugin, IPluginI18n, IHomeQuery
57
{
6-
public class Main : IPlugin, IPluginI18n, IHomeQuery
7-
{
8-
internal static PluginInitContext Context { get; private set; }
8+
internal static PluginInitContext Context { get; private set; }
99

10-
public List<Result> Query(Query query)
11-
{
12-
return QueryResults(query);
13-
}
10+
public void Init(PluginInitContext context)
11+
{
12+
Context = context;
13+
}
1414

15-
public List<Result> HomeQuery()
16-
{
17-
return QueryResults();
18-
}
15+
public List<Result> Query(Query query)
16+
{
17+
return QueryResults(query);
18+
}
1919

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;
2424

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 =>
3542
{
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+
}
4949

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())
5154
{
52-
var nonGlobalPlugins = new Dictionary<string, PluginPair>();
53-
foreach (var plugin in Context.API.GetAllPlugins())
55+
foreach (var actionKeyword in plugin.Metadata.ActionKeywords)
5456
{
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;
5959

60-
// Skip dulpicated keywords
61-
if (nonGlobalPlugins.ContainsKey(actionKeyword)) continue;
60+
// Skip dulpicated keywords
61+
if (nonGlobalPlugins.ContainsKey(actionKeyword)) continue;
6262

63-
nonGlobalPlugins.Add(actionKeyword, plugin);
64-
}
63+
nonGlobalPlugins.Add(actionKeyword, plugin);
6564
}
66-
return nonGlobalPlugins;
6765
}
66+
return nonGlobalPlugins;
67+
}
6868

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+
}
7373

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+
}
7878

79-
public string GetTranslatedPluginDescription()
80-
{
81-
return Localize.flowlauncher_plugin_pluginindicator_plugin_description();
82-
}
79+
public List<Result> HomeQuery()
80+
{
81+
return QueryResults();
8382
}
8483
}

0 commit comments

Comments
 (0)