2014-01-03 10:16:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2014-03-13 14:31:44 +00:00
|
|
|
|
using Wox.Helper;
|
2014-07-18 12:00:55 +00:00
|
|
|
|
using Wox.Infrastructure.Storage.UserSettings;
|
2014-01-29 10:33:24 +00:00
|
|
|
|
using Wox.Plugin;
|
2014-01-03 10:16:05 +00:00
|
|
|
|
|
2014-07-05 15:10:34 +00: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 10:16:05 +00:00
|
|
|
|
|
2014-07-05 15:10:34 +00:00
|
|
|
|
public static void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
plugins.Clear();
|
2014-07-06 14:57:11 +00:00
|
|
|
|
List<PluginMetadata> pluginMetadatas = PluginConfigLoader.ParsePluginsConfig();
|
2014-03-25 09:08:35 +00:00
|
|
|
|
|
2014-07-09 10:15:23 +00:00
|
|
|
|
plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas));
|
|
|
|
|
|
plugins.AddRange(new BasePluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
|
2014-01-12 10:15:30 +00:00
|
|
|
|
|
2014-07-05 15:10:34 +00:00
|
|
|
|
Forker forker = new Forker();
|
2014-07-10 10:39:04 +00:00
|
|
|
|
foreach (PluginPair pluginPair in plugins)
|
2014-07-05 15:10:34 +00:00
|
|
|
|
{
|
2014-07-10 10:39:04 +00:00
|
|
|
|
PluginPair pair = pluginPair;
|
|
|
|
|
|
forker.Fork(() => pair.Plugin.Init(new PluginInitContext()
|
2014-07-05 15:10:34 +00:00
|
|
|
|
{
|
2014-07-10 10:39:04 +00:00
|
|
|
|
CurrentPluginMetadata = pair.Metadata,
|
2014-07-18 12:00:55 +00:00
|
|
|
|
Proxy = HttpProxy.Instance,
|
2014-07-10 10:39:04 +00:00
|
|
|
|
API = App.Window
|
|
|
|
|
|
}));
|
2014-07-05 15:10:34 +00:00
|
|
|
|
}
|
2014-01-07 15:27:05 +00:00
|
|
|
|
|
2014-10-22 14:49:34 +00:00
|
|
|
|
//if plugin init do heavy works, join here will block the UI
|
|
|
|
|
|
//forker.Join();
|
2014-07-05 15:10:34 +00:00
|
|
|
|
}
|
2014-01-07 15:27:05 +00:00
|
|
|
|
|
2014-07-05 15:10:34 +00:00
|
|
|
|
public static List<PluginPair> AllPlugins
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return plugins;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-03-22 08:50:47 +00:00
|
|
|
|
|
2014-07-05 15:10:34 +00:00
|
|
|
|
public static bool HitThirdpartyKeyword(Query query)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(query.ActionName)) return false;
|
2014-03-22 08:50:47 +00:00
|
|
|
|
|
2014-07-05 15:10:34 +00:00
|
|
|
|
return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName);
|
|
|
|
|
|
}
|
2014-05-08 22:58:38 +00:00
|
|
|
|
|
2014-07-05 15:10:34 +00:00
|
|
|
|
public static void ActivatePluginDebugger(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebuggerMode = path;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-01-03 10:16:05 +00:00
|
|
|
|
}
|