2023-04-25 12:04:08 +00:00
|
|
|
|
using System.Diagnostics;
|
2022-10-23 09:05:12 +00:00
|
|
|
|
using System.IO;
|
2023-11-04 02:16:51 +00:00
|
|
|
|
using System.Text.Json;
|
2022-10-23 09:05:12 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2022-10-23 21:47:09 +00:00
|
|
|
|
using Flow.Launcher.Plugin;
|
2022-10-23 09:05:12 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Core.Plugin
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Execution of JavaScript & TypeScript plugins
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class NodePlugin : JsonRPCPlugin
|
|
|
|
|
|
{
|
2022-10-23 21:47:09 +00:00
|
|
|
|
private readonly ProcessStartInfo _startInfo;
|
|
|
|
|
|
|
2022-10-23 09:05:12 +00:00
|
|
|
|
public NodePlugin(string filename)
|
|
|
|
|
|
{
|
2022-10-23 21:47:09 +00:00
|
|
|
|
_startInfo = new ProcessStartInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
FileName = filename,
|
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
|
RedirectStandardError = true
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-10-23 09:05:12 +00:00
|
|
|
|
|
2022-10-23 21:47:09 +00:00
|
|
|
|
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
|
|
|
|
|
|
{
|
2024-02-10 13:59:52 +00:00
|
|
|
|
_startInfo.ArgumentList[1] = JsonSerializer.Serialize(request, RequestSerializeOption);
|
2022-10-23 21:47:09 +00:00
|
|
|
|
return ExecuteAsync(_startInfo, token);
|
2022-10-23 09:05:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
|
2022-11-30 10:06:54 +00:00
|
|
|
|
{
|
2022-10-23 21:47:09 +00:00
|
|
|
|
// since this is not static, request strings will build up in ArgumentList if index is not specified
|
2024-02-10 13:59:52 +00:00
|
|
|
|
_startInfo.ArgumentList[1] = JsonSerializer.Serialize(rpcRequest, RequestSerializeOption);
|
2022-10-23 21:47:09 +00:00
|
|
|
|
return Execute(_startInfo);
|
2022-10-23 09:05:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-23 21:47:09 +00:00
|
|
|
|
public override async Task InitAsync(PluginInitContext context)
|
2022-10-23 09:05:12 +00:00
|
|
|
|
{
|
2022-10-23 21:47:09 +00:00
|
|
|
|
_startInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
|
2024-02-10 13:59:52 +00:00
|
|
|
|
_startInfo.ArgumentList.Add(string.Empty);
|
2022-10-23 21:47:09 +00:00
|
|
|
|
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
2023-11-04 02:16:51 +00:00
|
|
|
|
await base.InitAsync(context);
|
2022-10-23 09:05:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|