PowerToys/WinAlfred/PluginLoader/Plugins.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2014-01-03 18:16:05 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2014-01-03 23:52:36 +08:00
using System.Threading;
2014-01-03 18:16:05 +08:00
using WinAlfred.Plugin;
namespace WinAlfred.PluginLoader
{
public static class Plugins
{
private static List<PluginPair> plugins = new List<PluginPair>();
2014-01-03 23:52:36 +08:00
public static void Init(MainWindow window)
2014-01-03 18:16:05 +08:00
{
plugins.Clear();
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
2014-01-03 23:52:36 +08:00
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
{
IPlugin plugin1 = plugin;
2014-01-11 00:19:14 +08:00
ThreadPool.QueueUserWorkItem(o =>
2014-01-03 23:52:36 +08:00
{
2014-01-11 00:19:14 +08:00
plugin1.Init(new PluginInitContext()
{
Plugins = plugins,
ChangeQuery = s => window.ChangeQuery(s),
CloseApp = window.CloseApp,
HideApp = window.HideApp,
ShowApp = window.ShowApp,
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
});
2014-01-09 22:16:19 +08:00
});
2014-01-03 23:52:36 +08:00
}
2014-01-03 18:16:05 +08:00
}
public static List<PluginPair> AllPlugins
{
get { return plugins; }
}
2014-01-07 23:27:05 +08: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 18:16:05 +08:00
}
}