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

58 lines
1.7 KiB
C#
Raw Normal View History

2016-05-07 15:56:29 +00:00
using System;
using System.Diagnostics;
2021-02-08 06:37:37 +00:00
using System.Threading;
using System.Threading.Tasks;
2020-04-21 09:12:17 +00:00
using Flow.Launcher.Plugin;
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 override string SupportedLanguage { get; set; } = AllowedLanguage.Executable;
public ExecutablePlugin(string filename)
{
_startInfo = new ProcessStartInfo
{
FileName = filename,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
}
2021-02-08 06:37:37 +00:00
protected override Task<string> ExecuteQueryAsync(Query query, CancellationToken token)
2016-05-07 15:56:29 +00:00
{
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
{
Method = "query",
2021-02-08 06:37:37 +00:00
Parameters = new object[] {query.Search},
2016-05-07 15:56:29 +00:00
};
_startInfo.Arguments = $"\"{request}\"";
2021-02-08 06:37:37 +00:00
return ExecuteAsync(_startInfo, token);
2016-05-07 15:56:29 +00:00
}
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
{
_startInfo.Arguments = $"\"{rpcRequest}\"";
return Execute(_startInfo);
2016-05-07 15:56:29 +00:00
}
2017-04-11 13:34:04 +00:00
2021-02-08 06:37:37 +00:00
protected override string ExecuteContextMenu(Result selectedResult)
{
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
{
2017-04-11 13:34:04 +00:00
Method = "contextmenu",
2021-02-08 06:37:37 +00:00
Parameters = new object[] {selectedResult.ContextData},
2017-04-11 13:34:04 +00:00
};
_startInfo.Arguments = $"\"{request}\"";
return Execute(_startInfo);
2017-04-11 13:34:04 +00:00
}
2016-05-07 15:56:29 +00:00
}
}