2022-09-01 02:34:47 +00:00
|
|
|
|
using System;
|
2023-03-26 19:04:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-09-01 02:34:47 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
2023-07-03 08:19:27 +00:00
|
|
|
|
using System.IO.Pipelines;
|
2023-06-02 15:05:09 +00:00
|
|
|
|
using System.Text;
|
2022-09-01 02:34:47 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2023-06-02 15:05:09 +00:00
|
|
|
|
using System.Windows.Input;
|
2023-06-24 16:43:21 +00:00
|
|
|
|
using Flow.Launcher.Core.Plugin.JsonRPCV2Models;
|
2022-09-01 02:34:47 +00:00
|
|
|
|
using Flow.Launcher.Infrastructure;
|
|
|
|
|
|
using Flow.Launcher.Plugin;
|
2023-06-02 15:05:09 +00:00
|
|
|
|
using Microsoft.VisualStudio.Threading;
|
2023-07-03 08:19:27 +00:00
|
|
|
|
using Nerdbank.Streams;
|
2023-06-02 15:05:09 +00:00
|
|
|
|
using StreamJsonRpc;
|
2022-09-01 02:34:47 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Core.Plugin
|
|
|
|
|
|
{
|
2023-07-03 08:44:50 +00:00
|
|
|
|
internal sealed class PythonPluginV2 : ProcessStreamPluginV2
|
2022-09-01 02:34:47 +00:00
|
|
|
|
{
|
2023-07-03 08:44:50 +00:00
|
|
|
|
protected override ProcessStartInfo StartInfo { get; set; }
|
2024-02-19 05:46:24 +00:00
|
|
|
|
|
2022-09-01 02:34:47 +00:00
|
|
|
|
public PythonPluginV2(string filename)
|
|
|
|
|
|
{
|
2024-02-19 05:46:24 +00:00
|
|
|
|
StartInfo = new ProcessStartInfo { FileName = filename, };
|
2022-09-01 02:34:47 +00:00
|
|
|
|
|
|
|
|
|
|
var path = Path.Combine(Constant.ProgramDirectory, JsonRpc);
|
2023-07-03 08:44:50 +00:00
|
|
|
|
StartInfo.EnvironmentVariables["PYTHONPATH"] = path;
|
2022-09-01 02:34:47 +00:00
|
|
|
|
|
|
|
|
|
|
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
2023-07-03 08:44:50 +00:00
|
|
|
|
StartInfo.ArgumentList.Add("-B");
|
2023-06-24 16:43:21 +00:00
|
|
|
|
}
|
2024-02-19 05:46:24 +00:00
|
|
|
|
|
2024-02-16 04:06:19 +00:00
|
|
|
|
public override async Task InitAsync(PluginInitContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
|
|
|
|
|
|
await base.InitAsync(context);
|
|
|
|
|
|
}
|
2024-02-19 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
protected override MessageHandlerType MessageHandler { get; } = MessageHandlerType.NewLineDelimited;
|
2022-09-01 02:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|