PowerToys/Wox/PluginLoader/Plugins.cs

59 lines
1.7 KiB
C#
Raw Normal View History

2014-01-03 18:16:05 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2014-11-27 12:14:02 +08:00
using System.Threading;
2014-03-13 22:31:44 +08:00
using Wox.Helper;
2014-12-21 22:03:03 +08:00
using Wox.Infrastructure;
using Wox.Infrastructure.Http;
2014-07-18 20:00:55 +08:00
using Wox.Infrastructure.Storage.UserSettings;
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();
2014-07-06 22:57:11 +08:00
List<PluginMetadata> pluginMetadatas = PluginConfigLoader.ParsePluginsConfig();
2014-07-09 18:15:23 +08:00
plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas));
plugins.AddRange(new BasePluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
2014-01-12 18:15:30 +08:00
foreach (PluginPair pluginPair in plugins)
2014-07-05 23:10:34 +08:00
{
PluginPair pair = pluginPair;
2014-11-27 12:14:02 +08:00
ThreadPool.QueueUserWorkItem(o => pair.Plugin.Init(new PluginInitContext()
2014-07-05 23:10:34 +08:00
{
CurrentPluginMetadata = pair.Metadata,
2014-07-18 20:00:55 +08:00
Proxy = HttpProxy.Instance,
API = App.Window
}));
2014-07-05 23:10:34 +08:00
}
}
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
}