mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 03:37:10 +08:00
dc3b01dc15
1. Fix can't find Result.ctor bug for plugin introduced in c0889de1f9ae460b2cc189eb59e5bd90ddb7d17e 2. use %APPDATA% for all data, part of #389 3. MISC
59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
using System.Diagnostics;
|
|
using System.IO;
|
|
using Wox.Core.UserSettings;
|
|
using Wox.Infrastructure;
|
|
using Wox.Plugin;
|
|
|
|
namespace Wox.Core.Plugin
|
|
{
|
|
internal class PythonPlugin : JsonRPCPlugin
|
|
{
|
|
private static readonly string PythonHome = Path.Combine(Infrastructure.Wox.ProgramPath, "PythonHome");
|
|
private readonly ProcessStartInfo _startInfo;
|
|
|
|
public override string SupportedLanguage => AllowedLanguage.Python;
|
|
|
|
public PythonPlugin()
|
|
{
|
|
_startInfo = new ProcessStartInfo
|
|
{
|
|
UseShellExecute = false,
|
|
CreateNoWindow = true,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true
|
|
};
|
|
string additionalPythonPath = $"{Path.Combine(PythonHome, "DLLs")};{Path.Combine(PythonHome, "Lib", "site-packages")}";
|
|
if (!_startInfo.EnvironmentVariables.ContainsKey("PYTHONPATH"))
|
|
{
|
|
|
|
_startInfo.EnvironmentVariables.Add("PYTHONPATH", additionalPythonPath);
|
|
}
|
|
else
|
|
{
|
|
_startInfo.EnvironmentVariables["PYTHONPATH"] = additionalPythonPath;
|
|
}
|
|
}
|
|
|
|
protected override string ExecuteQuery(Query query)
|
|
{
|
|
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
|
|
{
|
|
Method = "query",
|
|
Parameters = new object[] { query.GetAllRemainingParameter() },
|
|
HttpProxy = HttpProxy.Instance
|
|
};
|
|
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
|
_startInfo.FileName = Path.Combine(PythonHome, "pythonw.exe");
|
|
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
|
|
|
|
return Execute(_startInfo);
|
|
}
|
|
|
|
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
|
|
{
|
|
_startInfo.FileName = Path.Combine(PythonHome, "pythonw.exe");
|
|
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\"";
|
|
return Execute(_startInfo);
|
|
}
|
|
}
|
|
} |