mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
76 lines
1.9 KiB
C#
76 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
using System.Threading.Channels;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using Flow.Launcher.Core.Plugin.JsonRPCV2Models;
|
|
using Flow.Launcher.Plugin;
|
|
using StreamJsonRpc;
|
|
|
|
|
|
namespace Flow.Launcher.Core.Plugin
|
|
{
|
|
internal abstract class JsonRpcPluginV2 : JsonRPCPluginBase
|
|
{
|
|
public abstract string SupportedLanguage { get; set; }
|
|
|
|
public const string JsonRpc = "JsonRPC";
|
|
|
|
protected abstract JsonRpc Rpc { get; set; }
|
|
|
|
protected StreamReader ErrorStream { get; set; }
|
|
|
|
|
|
protected override async Task<bool> ExecuteResultAsync(JsonRPCResult result)
|
|
{
|
|
try
|
|
{
|
|
var res = await Rpc.InvokeAsync<JsonRPCExecuteResponse>(result.JsonRPCAction.Method, argument: result.JsonRPCAction.Parameters);
|
|
|
|
return res.Hide;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public override async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
|
|
{
|
|
try
|
|
{
|
|
var res = await Rpc.InvokeAsync<JsonRPCQueryResponseModel>("query", query);
|
|
|
|
var results = ParseResults(res);
|
|
|
|
return results;
|
|
}
|
|
catch
|
|
{
|
|
return new List<Result>();
|
|
}
|
|
}
|
|
|
|
|
|
public override async Task InitAsync(PluginInitContext context)
|
|
{
|
|
await base.InitAsync(context);
|
|
|
|
_ = ReadErrorAsync();
|
|
|
|
async Task ReadErrorAsync()
|
|
{
|
|
var error = await ErrorStream.ReadToEndAsync();
|
|
|
|
if (!string.IsNullOrEmpty(error))
|
|
{
|
|
throw new Exception(error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|