PowerToys/Wox.Core/Plugin/PythonPlugin.cs

45 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using Wox.Core.UserSettings;
2014-01-29 18:33:24 +08:00
using Wox.Plugin;
2014-12-26 19:36:43 +08:00
namespace Wox.Core.Plugin
{
2014-12-26 19:36:43 +08:00
internal class PythonPlugin : JsonRPCPlugin
{
private readonly ProcessStartInfo _startInfo;
public override string SupportedLanguage { get; set; } = AllowedLanguage.Python;
public PythonPlugin(string filename)
2014-07-18 20:00:55 +08:00
{
_startInfo = new ProcessStartInfo
{
2016-05-05 19:30:23 +08:00
FileName = filename,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
2014-07-18 20:00:55 +08:00
}
2014-07-07 23:05:06 +08:00
protected override string ExecuteQuery(Query query)
2014-01-11 00:19:14 +08:00
{
2016-01-07 05:34:42 +08:00
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
{
Method = "query",
Parameters = new object[] { query.Search },
HttpProxy = HttpProxy.Instance
};
2014-07-18 20:00:55 +08:00
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
2014-07-18 20:00:55 +08:00
return Execute(_startInfo);
}
2014-12-26 19:36:43 +08:00
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
{
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\"";
return Execute(_startInfo);
}
}
2014-07-07 23:05:06 +08:00
}