From d4c9626cbf5f62fda084db5f6949b636b8da9265 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Wed, 9 Apr 2025 12:54:20 +0800
Subject: [PATCH] Improve code quality & Remove unused project reference
---
...low.Launcher.Plugin.PluginIndicator.csproj | 2 -
.../Main.cs | 41 ++++++++++++++-----
2 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj b/Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj
index 21d964c11..1e662de9e 100644
--- a/Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj
+++ b/Plugins/Flow.Launcher.Plugin.PluginIndicator/Flow.Launcher.Plugin.PluginIndicator.csproj
@@ -41,8 +41,6 @@
-
-
diff --git a/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs b/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs
index aea0d77a1..05e8d960f 100644
--- a/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs
@@ -1,20 +1,20 @@
using System.Collections.Generic;
using System.Linq;
-using Flow.Launcher.Core.Plugin;
namespace Flow.Launcher.Plugin.PluginIndicator
{
public class Main : IPlugin, IPluginI18n
{
- private PluginInitContext context;
+ internal PluginInitContext Context { get; private set; }
public List Query(Query query)
{
+ var nonGlobalPlugins = GetNonGlobalPlugins();
var results =
- from keyword in PluginManager.NonGlobalPlugins.Keys
- let plugin = PluginManager.NonGlobalPlugins[keyword].Metadata
- let keywordSearchResult = context.API.FuzzySearch(query.Search, keyword)
- let searchResult = keywordSearchResult.IsSearchPrecisionScoreMet() ? keywordSearchResult : context.API.FuzzySearch(query.Search, plugin.Name)
+ from keyword in nonGlobalPlugins.Keys
+ let plugin = nonGlobalPlugins[keyword].Metadata
+ let keywordSearchResult = Context.API.FuzzySearch(query.Search, keyword)
+ let searchResult = keywordSearchResult.IsSearchPrecisionScoreMet() ? keywordSearchResult : Context.API.FuzzySearch(query.Search, plugin.Name)
let score = searchResult.Score
where (searchResult.IsSearchPrecisionScoreMet()
|| string.IsNullOrEmpty(query.Search)) // To list all available action keywords
@@ -22,32 +22,51 @@ namespace Flow.Launcher.Plugin.PluginIndicator
select new Result
{
Title = keyword,
- SubTitle = string.Format(context.API.GetTranslation("flowlauncher_plugin_pluginindicator_result_subtitle"), plugin.Name),
+ SubTitle = string.Format(Context.API.GetTranslation("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}");
+ Context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}");
return false;
}
};
return results.ToList();
}
+ private Dictionary GetNonGlobalPlugins()
+ {
+ var nonGlobalPlugins = new Dictionary();
+ 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 void Init(PluginInitContext context)
{
- this.context = context;
+ Context = context;
}
public string GetTranslatedPluginTitle()
{
- return context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name");
+ return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_name");
}
public string GetTranslatedPluginDescription()
{
- return context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description");
+ return Context.API.GetTranslation("flowlauncher_plugin_pluginindicator_plugin_description");
}
}
}