mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Implement IInstantSearch for CMD and WebSearch plugin
This commit is contained in:
@@ -20,6 +20,9 @@ namespace Wox.Core.Plugin
|
||||
public static class PluginManager
|
||||
{
|
||||
public const string ActionKeywordWildcardSign = "*";
|
||||
private static List<PluginMetadata> pluginMetadatas;
|
||||
private static List<IInstantSearch> instantSearches = new List<IInstantSearch>();
|
||||
|
||||
|
||||
public static String DebuggerMode { get; private set; }
|
||||
public static IPublicAPI API { get; private set; }
|
||||
@@ -31,7 +34,6 @@ namespace Wox.Core.Plugin
|
||||
/// </summary>
|
||||
private static List<string> pluginDirectories = new List<string>();
|
||||
|
||||
|
||||
private static void SetupPluginDirectories()
|
||||
{
|
||||
pluginDirectories.Add(PluginDirectory);
|
||||
@@ -72,7 +74,7 @@ namespace Wox.Core.Plugin
|
||||
API = api;
|
||||
plugins.Clear();
|
||||
|
||||
List<PluginMetadata> pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
||||
pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
||||
plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas));
|
||||
plugins.AddRange(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
|
||||
|
||||
@@ -95,6 +97,8 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
LoadInstantSearches();
|
||||
}
|
||||
|
||||
public static void InstallPlugin(string path)
|
||||
@@ -140,6 +144,46 @@ namespace Wox.Core.Plugin
|
||||
DebuggerMode = path;
|
||||
}
|
||||
|
||||
public static bool IsInstantSearch(string query)
|
||||
{
|
||||
return LoadInstantSearches().Any(o => o.IsInstantSearch(query));
|
||||
}
|
||||
|
||||
private static List<IInstantSearch> LoadInstantSearches()
|
||||
{
|
||||
if (instantSearches.Count > 0) return instantSearches;
|
||||
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
||||
|
||||
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IInstantSearch))).ToList();
|
||||
if (types.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
instantSearches.Add(Activator.CreateInstance(type) as IInstantSearch);
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return instantSearches;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get specified plugin, return null if not found
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user