From ae121895e99aca706df90a42fa310c65fe29d62a Mon Sep 17 00:00:00 2001 From: roose Date: Sat, 7 May 2016 21:56:29 +0600 Subject: [PATCH] Added solution for executable plugins --- Wox.Core/Plugin/ExecutablePlugin.cs | 45 +++++++++++++++++++++++++++++ Wox.Core/Plugin/PluginManager.cs | 3 +- Wox.Core/Plugin/PluginsLoader.cs | 13 +++++++++ Wox.Core/Wox.Core.csproj | 1 + 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Wox.Core/Plugin/ExecutablePlugin.cs diff --git a/Wox.Core/Plugin/ExecutablePlugin.cs b/Wox.Core/Plugin/ExecutablePlugin.cs new file mode 100644 index 0000000000..0bb27ae860 --- /dev/null +++ b/Wox.Core/Plugin/ExecutablePlugin.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 1013b1d1c8..2b8ee81cba 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -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 diff --git a/Wox.Core/Plugin/PluginsLoader.cs b/Wox.Core/Plugin/PluginsLoader.cs index b748712fa1..8817de03a2 100644 --- a/Wox.Core/Plugin/PluginsLoader.cs +++ b/Wox.Core/Plugin/PluginsLoader.cs @@ -110,5 +110,18 @@ namespace Wox.Core.Plugin }); return plugins; } + + public static IEnumerable ExecutablePlugins(IEnumerable 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; + } + } } \ No newline at end of file diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 082ff63f77..78e8244d23 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -65,6 +65,7 @@ Properties\SolutionAssemblyInfo.cs +