Skip to content

Commit d4c9626

Browse files
committed
Improve code quality & Remove unused project reference
1 parent 826bc42 commit d4c9626

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
</ItemGroup>
4242

4343
<ItemGroup>
44-
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
45-
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
4644
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
4745
</ItemGroup>
4846

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,72 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Flow.Launcher.Core.Plugin;
43

54
namespace Flow.Launcher.Plugin.PluginIndicator
65
{
76
public class Main : IPlugin, IPluginI18n
87
{
9-
private PluginInitContext context;
8+
internal PluginInitContext Context { get; private set; }
109

1110
public List<Result> Query(Query query)
1211
{
12+
var nonGlobalPlugins = GetNonGlobalPlugins();
1313
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)
1818
let score = searchResult.Score
1919
where (searchResult.IsSearchPrecisionScoreMet()
2020
|| string.IsNullOrEmpty(query.Search)) // To list all available action keywords
2121
&& !plugin.Disabled
2222
select new Result
2323
{
2424
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),
2626
Score = score,
2727
IcoPath = plugin.IcoPath,
2828
AutoCompleteText = $"{keyword}{Plugin.Query.TermSeparator}",
2929
Action = c =>
3030
{
31-
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}");
31+
Context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}");
3232
return false;
3333
}
3434
};
3535
return results.ToList();
3636
}
3737

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+
3857
public void Init(PluginInitContext context)
3958
{
40-
this.context = context;
59+
Context = context;
4160
}
4261

4362
public string GetTranslatedPluginTitle()
4463
{
45-
return context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name");
64+
return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name");
4665
}
4766

4867
public string GetTranslatedPluginDescription()
4968
{
50-
return context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description");
69+
return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description");
5170
}
5271
}
5372
}

0 commit comments

Comments
 (0)