mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Added solution for executable plugins
This commit is contained in:
45
Wox.Core/Plugin/ExecutablePlugin.cs
Normal file
45
Wox.Core/Plugin/ExecutablePlugin.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user