Added solution for executable plugins

This commit is contained in:
roose
2016-05-07 21:56:29 +06:00
committed by bao-qian
parent 11ecf20f89
commit ae121895e9
4 changed files with 61 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
using System;
using System.Diagnostics;
using Wox.Core.UserSettings;
using Wox.Plugin;
namespace Wox.Core.Plugin
{
internal class ExecutablePlugin : JsonRPCPlugin
{
private readonly ProcessStartInfo _startInfo;
public override string SupportedLanguage { get; set; } = AllowedLanguage.Executable;
public ExecutablePlugin(string filename)
{
_startInfo = new ProcessStartInfo
{
FileName = filename,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
}
protected override string ExecuteQuery(Query query)
{
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
{
Method = "query",
Parameters = new object[] { query.Search },
HttpProxy = HttpProxy.Instance
};
_startInfo.Arguments = $"\"{request}\"";
return Execute(_startInfo);
}
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
{
_startInfo.Arguments = $"\"{rpcRequest}\"";
return Execute(_startInfo);
}
}
}

View File

@@ -63,7 +63,8 @@ namespace Wox.Core.Plugin
{
_settings = settings;
var plugins = PluginsLoader.PythonPlugins(_metadatas, _settings.PythonDirectory);
AllPlugins = AllPlugins.Concat(plugins).ToList();
var executable_plugins = PluginsLoader.ExecutablePlugins(_metadatas);
AllPlugins = AllPlugins.Concat(plugins).Concat(executable_plugins).ToList();
_settings.UpdatePluginSettings(AllPlugins);
//load plugin i18n languages

View File

@@ -110,5 +110,18 @@ namespace Wox.Core.Plugin
});
return plugins;
}
public static IEnumerable<PluginPair> ExecutablePlugins(IEnumerable<PluginMetadata> source)
{
var metadatas = source.Where(o => o.Language.ToUpper() == AllowedLanguage.Executable);
var plugins = metadatas.Select(metadata => new PluginPair
{
Plugin = new ExecutablePlugin(metadata.ExecuteFilePath),
Metadata = metadata
});
return plugins;
}
}
}

View File

@@ -65,6 +65,7 @@
<Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="APIServer.cs" />
<Compile Include="Plugin\ExecutablePlugin.cs" />
<Compile Include="Plugin\PluginsLoader.cs" />
<Compile Include="Updater\Release.cs" />
<Compile Include="Updater\UpdaterManager.cs" />