PowerToys/Wox/PluginLoader/Plugins.cs

65 lines
1.9 KiB
C#
Raw Normal View History

2014-01-03 18:16:05 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2014-03-13 22:31:44 +08:00
using Wox.Helper;
2014-01-29 18:33:24 +08:00
using Wox.Plugin;
2014-01-03 18:16:05 +08:00
2014-07-05 23:10:34 +08:00
namespace Wox.PluginLoader
{
public static class Plugins
{
public static String DebuggerMode { get; private set; }
private static List<PluginPair> plugins = new List<PluginPair>();
2014-01-03 18:16:05 +08:00
2014-07-05 23:10:34 +08:00
public static void Init()
{
plugins.Clear();
BasePluginLoader.ParsePluginsConfig();
2014-07-05 23:10:34 +08:00
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
plugins.AddRange(new ExecutablePluginLoader().LoadPlugin());
2014-01-12 18:15:30 +08:00
2014-07-05 23:10:34 +08:00
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
};
2014-01-03 18:16:05 +08:00
2014-07-05 23:10:34 +08:00
forker.Fork(() => plugin1.Init(pluginPair.InitContext));
}
}
2014-01-07 23:27:05 +08:00
2014-07-05 23:10:34 +08:00
forker.Join();
}
2014-01-07 23:27:05 +08:00
2014-07-05 23:10:34 +08:00
public static List<PluginPair> AllPlugins
{
get
{
return plugins;
}
}
2014-07-05 23:10:34 +08:00
public static bool HitThirdpartyKeyword(Query query)
{
if (string.IsNullOrEmpty(query.ActionName)) return false;
2014-07-05 23:10:34 +08:00
return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName);
}
2014-07-05 23:10:34 +08:00
public static void ActivatePluginDebugger(string path)
{
DebuggerMode = path;
}
}
2014-01-03 18:16:05 +08:00
}