mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-04 20:21:18 +08:00
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using Microsoft.CSharp;
|
|
using WinAlfred.Plugin;
|
|
|
|
namespace WinAlfred.PluginLoader
|
|
{
|
|
public static class Plugins
|
|
{
|
|
private static List<PluginPair> plugins = new List<PluginPair>();
|
|
|
|
public static void Init(MainWindow window)
|
|
{
|
|
plugins.Clear();
|
|
BasePluginLoader.ParsePluginsConfig();
|
|
|
|
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
|
|
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
|
|
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
|
{
|
|
IPlugin plugin1 = plugin;
|
|
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
|
|
{
|
|
Plugins = plugins,
|
|
ChangeQuery = s => window.ChangeQuery(s),
|
|
CloseApp = window.CloseApp,
|
|
HideApp = window.HideApp,
|
|
ShowApp = () => window.ShowApp(null),
|
|
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
|
|
}));
|
|
}
|
|
}
|
|
|
|
public static List<PluginPair> AllPlugins
|
|
{
|
|
get { return plugins; }
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|