mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 03:37:10 +08:00
64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Wox.Helper;
|
|
using Wox.Plugin;
|
|
|
|
namespace Wox.PluginLoader
|
|
{
|
|
public static class Plugins
|
|
{
|
|
public static String DebuggerMode { get; private set; }
|
|
private static List<PluginPair> plugins = new List<PluginPair>();
|
|
|
|
public static void Init()
|
|
{
|
|
plugins.Clear();
|
|
List<PluginMetadata> pluginMetadatas = PluginConfigLoader.ParsePluginsConfig();
|
|
|
|
plugins.AddRange(new CSharpPluginConfigLoader().LoadPlugin(pluginMetadatas));
|
|
plugins.AddRange(new BasePluginLoader<PythonPluginWrapper>().LoadPlugin(pluginMetadatas));
|
|
|
|
Forker forker = new Forker();
|
|
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
|
{
|
|
IPlugin plugin1 = plugin;
|
|
PluginPair pluginPair = plugins.FirstOrDefault(o => o.Plugin == plugin1);
|
|
if (pluginPair != null)
|
|
{
|
|
PluginMetadata metadata = pluginPair.Metadata;
|
|
pluginPair.InitContext = new PluginInitContext()
|
|
{
|
|
CurrentPluginMetadata = metadata,
|
|
API = App.Window
|
|
};
|
|
|
|
forker.Fork(() => plugin1.Init(pluginPair.InitContext));
|
|
}
|
|
}
|
|
|
|
forker.Join();
|
|
}
|
|
|
|
public static List<PluginPair> AllPlugins
|
|
{
|
|
get
|
|
{
|
|
return plugins;
|
|
}
|
|
}
|
|
|
|
public static bool HitThirdpartyKeyword(Query query)
|
|
{
|
|
if (string.IsNullOrEmpty(query.ActionName)) return false;
|
|
|
|
return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName);
|
|
}
|
|
|
|
public static void ActivatePluginDebugger(string path)
|
|
{
|
|
DebuggerMode = path;
|
|
}
|
|
}
|
|
}
|