mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
* Use Flow.Launcher.Localization to improve code quality * Code cleanup * Improve code quality * Improve code quality * Use internal static Context & Improve code quality * Use Flow.Launcher.Localization to improve code quality * Code cleanup * Use Flow.Launcher.Localization to improve code quality * Improve code quality * Improve code quality * Use Flow.Launcher.Localization to improve code quality * Fix logic issue * Fix the variable name typo * Fix redundant boolean cast and ensure consistent default value handling * Use Flow.Launcher.Localization to improve code quality * Revert namespace styles * Fix indent format * Revert namespace style * Fix indent format * Fix namespace style * Fix indent format * Fix indent format
84 lines
3 KiB
C#
84 lines
3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Flow.Launcher.Plugin.PluginIndicator
|
|
{
|
|
public class Main : IPlugin, IPluginI18n, IHomeQuery
|
|
{
|
|
internal static PluginInitContext Context { get; private set; }
|
|
|
|
public void Init(PluginInitContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
|
|
public List<Result> Query(Query query)
|
|
{
|
|
return QueryResults(query);
|
|
}
|
|
|
|
private static List<Result> QueryResults(Query query = null)
|
|
{
|
|
var nonGlobalPlugins = GetNonGlobalPlugins();
|
|
var querySearch = query?.Search ?? string.Empty;
|
|
|
|
var results =
|
|
from keyword in nonGlobalPlugins.Keys
|
|
let plugin = nonGlobalPlugins[keyword].Metadata
|
|
let keywordSearchResult = Context.API.FuzzySearch(querySearch, keyword)
|
|
let searchResult = keywordSearchResult.IsSearchPrecisionScoreMet() ? keywordSearchResult : Context.API.FuzzySearch(querySearch, plugin.Name)
|
|
let score = searchResult.Score
|
|
where (searchResult.IsSearchPrecisionScoreMet()
|
|
|| string.IsNullOrEmpty(querySearch)) // To list all available action keywords
|
|
&& !plugin.Disabled
|
|
select new Result
|
|
{
|
|
Title = keyword,
|
|
SubTitle = Localize.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}");
|
|
return false;
|
|
}
|
|
};
|
|
return [.. results];
|
|
}
|
|
|
|
private static Dictionary<string, PluginPair> GetNonGlobalPlugins()
|
|
{
|
|
var nonGlobalPlugins = new Dictionary<string, PluginPair>();
|
|
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 string GetTranslatedPluginTitle()
|
|
{
|
|
return Localize.flowlauncher_plugin_pluginindicator_plugin_name();
|
|
}
|
|
|
|
public string GetTranslatedPluginDescription()
|
|
{
|
|
return Localize.flowlauncher_plugin_pluginindicator_plugin_description();
|
|
}
|
|
|
|
public List<Result> HomeQuery()
|
|
{
|
|
return QueryResults();
|
|
}
|
|
}
|
|
}
|