Flow.Launcher/Flow.Launcher.Core/Plugin/PythonPluginV2.cs

43 lines
1.4 KiB
C#
Raw Normal View History

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
{
internal sealed class PythonPluginV2 : ProcessStreamPluginV2
2022-09-01 02:34:47 +00:00
{
protected override ProcessStartInfo StartInfo { get; set; }
2022-09-01 02:34:47 +00:00
public PythonPluginV2(string filename)
{
StartInfo = new ProcessStartInfo { FileName = filename, };
2022-09-01 02:34:47 +00:00
var path = Path.Combine(Constant.ProgramDirectory, JsonRpc);
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
StartInfo.ArgumentList.Add("-B");
2023-06-24 16:43:21 +00:00
}
public override async Task InitAsync(PluginInitContext context)
{
StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
await base.InitAsync(context);
}
protected override MessageHandlerType MessageHandler { get; } = MessageHandlerType.NewLineDelimited;
2022-09-01 02:34:47 +00:00
}
}