Flow.Launcher/Flow.Launcher.Core/Plugin/ExecutablePlugin.cs
Jeremy bf0e4ba452 fix Executable plugin's JsonRPC request string
This is a fix of Executable plugin's JsonRPC request string for ProcessStartInfo, but tested and should be used specifically for Typescript + JavaScript plugin
2021-12-24 19:07:51 +11:00

43 lines
1.5 KiB
C#

using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Flow.Launcher.Plugin;
namespace Flow.Launcher.Core.Plugin
{
internal class ExecutablePlugin : JsonRPCPlugin
{
private readonly ProcessStartInfo _startInfo;
public override string SupportedLanguage { get; set; } = AllowedLanguage.Executable;
public ExecutablePlugin(string filename)
{
_startInfo = new ProcessStartInfo
{
FileName = filename,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
// required initialisation for below request calls
_startInfo.ArgumentList.Add(string.Empty);
}
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
{
// since this is not static, request strings will build up in ArgumentList if index is not specified
_startInfo.ArgumentList[0] = request.ToString();
return ExecuteAsync(_startInfo, token);
}
protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
{
// since this is not static, request strings will build up in ArgumentList if index is not specified
_startInfo.ArgumentList[0] = rpcRequest.ToString();
return Execute(_startInfo);
}
}
}