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-12 18:15:30 +08:00
|
|
|
|
using Microsoft.CSharp;
|
2014-03-13 22:31:44 +08:00
|
|
|
|
using Wox.Helper;
|
2014-03-19 01:27:59 +08:00
|
|
|
|
using Wox.Infrastructure;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Wox.Plugin;
|
2014-01-03 18:16:05 +08:00
|
|
|
|
|
2014-01-29 18:33:24 +08:00
|
|
|
|
namespace Wox.PluginLoader
|
2014-01-03 18:16:05 +08:00
|
|
|
|
{
|
|
|
|
|
public static class Plugins
|
|
|
|
|
{
|
|
|
|
|
private static List<PluginPair> plugins = new List<PluginPair>();
|
|
|
|
|
|
2014-01-26 21:18:01 +08:00
|
|
|
|
public static void Init()
|
2014-01-03 18:16:05 +08:00
|
|
|
|
{
|
|
|
|
|
plugins.Clear();
|
2014-01-12 18:15:30 +08:00
|
|
|
|
BasePluginLoader.ParsePluginsConfig();
|
|
|
|
|
|
2014-03-19 01:27:59 +08:00
|
|
|
|
if (CommonStorage.Instance.UserSetting.EnablePythonPlugins)
|
|
|
|
|
{
|
|
|
|
|
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-03 18:16:05 +08:00
|
|
|
|
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-25 00:21:16 +08:00
|
|
|
|
PluginPair pluginPair = plugins.FirstOrDefault(o => o.Plugin == plugin1);
|
|
|
|
|
if (pluginPair != null)
|
2014-01-03 23:52:36 +08:00
|
|
|
|
{
|
2014-01-25 00:21:16 +08:00
|
|
|
|
PluginMetadata metadata = pluginPair.Metadata;
|
|
|
|
|
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
|
|
|
|
|
{
|
|
|
|
|
Plugins = plugins,
|
2014-03-01 15:42:33 +08:00
|
|
|
|
CurrentPluginMetadata = metadata,
|
2014-03-13 22:31:44 +08:00
|
|
|
|
ChangeQuery = s => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ChangeQuery(s))),
|
|
|
|
|
CloseApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.CloseApp())),
|
|
|
|
|
HideApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.HideApp())),
|
|
|
|
|
ShowApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowApp())),
|
|
|
|
|
ShowMsg = (title, subTitle, iconPath) => App.Window.Dispatcher.Invoke(new Action(() =>
|
|
|
|
|
App.Window.ShowMsg(title, subTitle, iconPath))),
|
|
|
|
|
OpenSettingDialog = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.OpenSettingDialog())),
|
|
|
|
|
ShowCurrentResultItemTooltip = (msg) => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowCurrentResultItemTooltip(msg))),
|
|
|
|
|
ReloadPlugins = () => App.Window.Dispatcher.Invoke(new Action(() => Init())),
|
|
|
|
|
InstallPlugin = (filePath) => App.Window.Dispatcher.Invoke(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
PluginInstaller.Install(filePath);
|
|
|
|
|
})),
|
|
|
|
|
StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())),
|
|
|
|
|
StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())),
|
2014-03-21 03:53:18 +08:00
|
|
|
|
ShellRun = (cmd) => (bool) App.Window.Dispatcher.Invoke(new Func<bool>(() => App.Window.ShellRun(cmd))),
|
2014-01-25 00:21:16 +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
|
|
|
|
}
|
|
|
|
|
}
|