Flow.Launcher/Flow.Launcher.Core/Plugin/ExecutablePlugin.cs

43 lines
1.5 KiB
C#
Raw Permalink Normal View History

using System.Diagnostics;
2021-02-14 05:56:27 +00:00
using System.IO;
using System.Text.Json;
2021-02-08 06:37:37 +00:00
using System.Threading;
using System.Threading.Tasks;
2016-05-07 15:56:29 +00:00
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Core.Plugin
2016-05-07 15:56:29 +00:00
{
internal class ExecutablePlugin : JsonRPCPlugin
{
private readonly ProcessStartInfo _startInfo;
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);
2016-05-07 15:56:29 +00:00
}
2021-08-13 05:55:07 +00:00
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
2016-05-07 15:56:29 +00:00
{
// since this is not static, request strings will build up in ArgumentList if index is not specified
_startInfo.ArgumentList[0] = JsonSerializer.Serialize(request, RequestSerializeOption);
2021-02-08 06:37:37 +00:00
return ExecuteAsync(_startInfo, token);
2016-05-07 15:56:29 +00:00
}
2021-08-13 05:55:07 +00:00
protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
2016-05-07 15:56:29 +00:00
{
// since this is not static, request strings will build up in ArgumentList if index is not specified
_startInfo.ArgumentList[0] = JsonSerializer.Serialize(rpcRequest, RequestSerializeOption);
return Execute(_startInfo);
2016-05-07 15:56:29 +00:00
}
}
2021-12-22 10:22:21 +00:00
}