fix python plugin and node plugin

fix job process association the program plugin
This commit is contained in:
Hongtao Zhang 2024-02-15 22:06:19 -06:00
parent 2370ec9a43
commit a27d5336df
5 changed files with 28 additions and 29 deletions

View file

@ -15,8 +15,6 @@ namespace Flow.Launcher.Core.Plugin
{
internal abstract class JsonRPCPluginV2 : JsonRPCPluginBase, IAsyncDisposable, IAsyncReloadable, IResultUpdated
{
public abstract string SupportedLanguage { get; set; }
public const string JsonRpc = "JsonRPC";
protected abstract IDuplexPipe ClientPipe { get; set; }

View file

@ -10,21 +10,13 @@ namespace Flow.Launcher.Core.Plugin
/// <summary>
/// Execution of JavaScript & TypeScript plugins
/// </summary>
internal class NodePluginV2 : ProcessStreamPluginV2
internal sealed class NodePluginV2 : ProcessStreamPluginV2
{
public NodePluginV2(string filename)
{
StartInfo = new ProcessStartInfo
{
FileName = filename,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
StartInfo = new ProcessStartInfo { FileName = filename, };
}
public override string SupportedLanguage { get; set; }
protected override ProcessStartInfo StartInfo { get; set; }
public override async Task InitAsync(PluginInitContext context)

View file

@ -1,4 +1,6 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Pipelines;
@ -6,6 +8,7 @@ using System.Threading.Tasks;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Plugin;
using Meziantou.Framework.Win32;
using Microsoft.VisualBasic.ApplicationServices;
using Nerdbank.Streams;
namespace Flow.Launcher.Core.Plugin
@ -18,18 +21,18 @@ namespace Flow.Launcher.Core.Plugin
{
_jobObject.SetLimits(new JobObjectLimits()
{
Flags = JobObjectLimitFlags.KillOnJobClose | JobObjectLimitFlags.DieOnUnhandledException
Flags = JobObjectLimitFlags.KillOnJobClose | JobObjectLimitFlags.DieOnUnhandledException |
JobObjectLimitFlags.SilentBreakawayOk
});
_jobObject.AssignProcess(Process.GetCurrentProcess());
}
public override string SupportedLanguage { get; set; }
protected sealed override IDuplexPipe ClientPipe { get; set; }
protected sealed override IDuplexPipe ClientPipe { get; set; } = null!;
protected abstract ProcessStartInfo StartInfo { get; set; }
protected Process ClientProcess { get; set; }
protected Process ClientProcess { get; set; } = null!;
public override async Task InitAsync(PluginInitContext context)
{
@ -37,12 +40,18 @@ namespace Flow.Launcher.Core.Plugin
StartInfo.EnvironmentVariables["FLOW_PROGRAM_DIRECTORY"] = Constant.ProgramDirectory;
StartInfo.EnvironmentVariables["FLOW_APPLICATION_DIRECTORY"] = Constant.ApplicationDirectory;
StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
StartInfo.RedirectStandardError = true;
StartInfo.RedirectStandardInput = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.CreateNoWindow = true;
StartInfo.UseShellExecute = false;
StartInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
ClientProcess = Process.Start(StartInfo);
ArgumentNullException.ThrowIfNull(ClientProcess);
var process = Process.Start(StartInfo);
ArgumentNullException.ThrowIfNull(process);
ClientProcess = process;
_jobObject.AssignProcess(ClientProcess);
SetupPipe(ClientProcess);
ErrorStream = ClientProcess.StandardError;

View file

@ -18,7 +18,6 @@ namespace Flow.Launcher.Core.Plugin
{
internal sealed class PythonPluginV2 : ProcessStreamPluginV2
{
public override string SupportedLanguage { get; set; } = AllowedLanguage.Python;
protected override ProcessStartInfo StartInfo { get; set; }
public PythonPluginV2(string filename)
@ -26,11 +25,6 @@ namespace Flow.Launcher.Core.Plugin
StartInfo = new ProcessStartInfo
{
FileName = filename,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true
};
var path = Path.Combine(Constant.ProgramDirectory, JsonRpc);
@ -39,5 +33,11 @@ namespace Flow.Launcher.Core.Plugin
//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");
}
public override async Task InitAsync(PluginInitContext context)
{
StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
await base.InitAsync(context);
}
}
}

View file

@ -196,7 +196,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
FileName = FullPath,
WorkingDirectory = ParentDirectory,
UseShellExecute = true,
Verb = runAsAdmin ? "runas" : ""
Verb = runAsAdmin ? "runas" : "",
};
_ = Task.Run(() => Main.StartProcess(Process.Start, info));