2014-01-03 11:16:05 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2014-01-03 16:52:36 +01:00
|
|
|
|
using System.Threading;
|
2014-01-12 11:15:30 +01:00
|
|
|
|
using Microsoft.CSharp;
|
2014-01-29 11:33:24 +01:00
|
|
|
|
using Wox.Plugin;
|
2014-01-03 11:16:05 +01:00
|
|
|
|
|
2014-01-29 11:33:24 +01:00
|
|
|
|
namespace Wox.PluginLoader
|
2014-01-03 11:16:05 +01:00
|
|
|
|
{
|
|
|
|
|
public static class Plugins
|
|
|
|
|
{
|
|
|
|
|
private static List<PluginPair> plugins = new List<PluginPair>();
|
|
|
|
|
|
2014-01-26 14:18:01 +01:00
|
|
|
|
public static void Init()
|
2014-01-03 11:16:05 +01:00
|
|
|
|
{
|
|
|
|
|
plugins.Clear();
|
2014-01-12 11:15:30 +01:00
|
|
|
|
BasePluginLoader.ParsePluginsConfig();
|
|
|
|
|
|
2014-01-03 11:16:05 +01:00
|
|
|
|
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
|
|
|
|
|
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
|
2014-01-03 16:52:36 +01:00
|
|
|
|
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
|
|
|
|
{
|
|
|
|
|
IPlugin plugin1 = plugin;
|
2014-01-24 17:21:16 +01:00
|
|
|
|
PluginPair pluginPair = plugins.FirstOrDefault(o => o.Plugin == plugin1);
|
|
|
|
|
if (pluginPair != null)
|
2014-01-03 16:52:36 +01:00
|
|
|
|
{
|
2014-01-24 17:21:16 +01:00
|
|
|
|
PluginMetadata metadata = pluginPair.Metadata;
|
|
|
|
|
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
|
|
|
|
|
{
|
|
|
|
|
Plugins = plugins,
|
|
|
|
|
PluginMetadata = metadata,
|
2014-01-26 14:18:01 +01:00
|
|
|
|
ChangeQuery = s => App.Window.ChangeQuery(s),
|
|
|
|
|
CloseApp = App.Window.CloseApp,
|
|
|
|
|
HideApp = App.Window.HideApp,
|
|
|
|
|
ShowApp = () => App.Window.ShowApp(),
|
|
|
|
|
ShowMsg = (title, subTitle, iconPath) => App.Window.ShowMsg(title, subTitle, iconPath),
|
|
|
|
|
OpenSettingDialog = () => App.Window.OpenSettingDialog()
|
2014-01-24 17:21:16 +01:00
|
|
|
|
}));
|
|
|
|
|
}
|
2014-01-03 16:52:36 +01:00
|
|
|
|
}
|
2014-01-03 11:16:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<PluginPair> AllPlugins
|
|
|
|
|
{
|
|
|
|
|
get { return plugins; }
|
|
|
|
|
}
|
2014-01-07 16:27:05 +01:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2014-01-03 11:16:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|