Flow.Launcher/Wox/PluginLoader/Plugins.cs

60 lines
1.8 KiB
C#
Raw Normal View History

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-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();
foreach (PluginPair pluginPair in plugins)
2014-07-05 15:10:34 +00:00
{
PluginPair pair = pluginPair;
forker.Fork(() => pair.Plugin.Init(new PluginInitContext()
2014-07-05 15:10:34 +00:00
{
CurrentPluginMetadata = pair.Metadata,
2014-07-18 12:00:55 +00:00
Proxy = HttpProxy.Instance,
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-07-05 15:10:34 +00:00
public static bool HitThirdpartyKeyword(Query query)
{
if (string.IsNullOrEmpty(query.ActionName)) return false;
2014-07-05 15:10:34 +00:00
return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName);
}
2014-07-05 15:10:34 +00:00
public static void ActivatePluginDebugger(string path)
{
DebuggerMode = path;
}
}
2014-01-03 10:16:05 +00:00
}