2021-11-30 08:36:38 +00:00
|
|
|
using System;
|
2016-05-05 00:57:03 +00:00
|
|
|
using System.Diagnostics;
|
2016-06-21 23:42:24 +00:00
|
|
|
using System.IO;
|
2021-02-08 06:37:37 +00:00
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-04-21 09:12:17 +00:00
|
|
|
using Flow.Launcher.Infrastructure;
|
|
|
|
|
using Flow.Launcher.Plugin;
|
2013-12-20 17:20:17 +00:00
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
namespace Flow.Launcher.Core.Plugin
|
2013-12-20 17:20:17 +00:00
|
|
|
{
|
2022-09-01 02:37:29 +00:00
|
|
|
internal class PythonPlugin : JsonRPCPlugin
|
2013-12-20 17:20:17 +00:00
|
|
|
{
|
2016-01-08 01:55:24 +00:00
|
|
|
private readonly ProcessStartInfo _startInfo;
|
2016-05-05 00:57:03 +00:00
|
|
|
public override string SupportedLanguage { get; set; } = AllowedLanguage.Python;
|
2013-12-20 17:20:17 +00:00
|
|
|
|
2016-05-05 00:57:03 +00:00
|
|
|
public PythonPlugin(string filename)
|
2014-07-18 12:00:55 +00:00
|
|
|
{
|
2016-01-08 01:55:24 +00:00
|
|
|
_startInfo = new ProcessStartInfo
|
|
|
|
|
{
|
2016-05-05 11:30:23 +00:00
|
|
|
FileName = filename,
|
2016-01-08 01:55:24 +00:00
|
|
|
UseShellExecute = false,
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
RedirectStandardOutput = true,
|
2016-06-21 23:42:24 +00:00
|
|
|
RedirectStandardError = true,
|
2016-01-08 01:55:24 +00:00
|
|
|
};
|
2016-06-21 23:42:24 +00:00
|
|
|
|
|
|
|
|
// temp fix for issue #667
|
2022-09-01 02:34:47 +00:00
|
|
|
var path = Path.Combine(Constant.ProgramDirectory, JsonRpc);
|
2016-06-21 23:42:24 +00:00
|
|
|
_startInfo.EnvironmentVariables["PYTHONPATH"] = path;
|
|
|
|
|
|
2021-11-30 08:36:38 +00:00
|
|
|
_startInfo.EnvironmentVariables["FLOW_VERSION"] = Constant.Version;
|
|
|
|
|
_startInfo.EnvironmentVariables["FLOW_PROGRAM_DIRECTORY"] = Constant.ProgramDirectory;
|
|
|
|
|
_startInfo.EnvironmentVariables["FLOW_APPLICATION_DIRECTORY"] = Constant.ApplicationDirectory;
|
|
|
|
|
|
|
|
|
|
|
2021-06-07 05:03:59 +00:00
|
|
|
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
|
|
|
|
_startInfo.ArgumentList.Add("-B");
|
2014-07-18 12:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-13 05:55:07 +00:00
|
|
|
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
|
2014-01-10 16:19:14 +00:00
|
|
|
{
|
2021-06-07 05:03:59 +00:00
|
|
|
_startInfo.ArgumentList[2] = request.ToString();
|
|
|
|
|
|
2021-02-08 06:37:37 +00:00
|
|
|
return ExecuteAsync(_startInfo, token);
|
2014-02-09 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-13 05:55:07 +00:00
|
|
|
protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
|
2014-02-09 12:55:18 +00:00
|
|
|
{
|
2021-06-07 05:03:59 +00:00
|
|
|
_startInfo.ArgumentList[2] = rpcRequest.ToString();
|
2022-09-01 02:34:47 +00:00
|
|
|
_startInfo.WorkingDirectory = Context.CurrentPluginMetadata.PluginDirectory;
|
2021-02-08 06:37:37 +00:00
|
|
|
// TODO: Async Action
|
2021-02-08 06:43:17 +00:00
|
|
|
return Execute(_startInfo);
|
2013-12-20 17:20:17 +00:00
|
|
|
}
|
2021-08-16 16:50:36 +00:00
|
|
|
public override async Task InitAsync(PluginInitContext context)
|
2021-06-07 05:03:59 +00:00
|
|
|
{
|
|
|
|
|
_startInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
|
|
|
|
|
_startInfo.ArgumentList.Add("");
|
2021-08-16 16:50:36 +00:00
|
|
|
await base.InitAsync(context);
|
2021-08-13 22:51:11 +00:00
|
|
|
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
2021-06-07 05:03:59 +00:00
|
|
|
}
|
2013-12-20 17:20:17 +00:00
|
|
|
}
|
2021-11-30 08:36:38 +00:00
|
|
|
}
|