Flow.Launcher/Flow.Launcher.Core/Plugin/JsonPRCModel.cs

63 lines
2.6 KiB
C#
Raw Permalink Normal View History

2021-06-10 07:08:10 +00:00
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Flow Launcher and other plugins,
2014-07-18 12:00:55 +00:00
* like python or other self-execute program. But, we added addtional infos (proxy and so on) into rpc request. Also, we didn't use the
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
*
* When execute a query:
2020-04-22 10:26:09 +00:00
* Flow Launcher -------JsonRPCServerRequestModel--------> client
* Flow Launcher <------JsonRPCQueryResponseModel--------- client
2014-07-18 12:00:55 +00:00
*
* When execute a action (which mean user select an item in reulst item):
2020-04-22 10:26:09 +00:00
* Flow Launcher -------JsonRPCServerRequestModel--------> client
* Flow Launcher <------JsonRPCResponseModel-------------- client
2014-07-18 12:00:55 +00:00
*
*/
using System.Collections.Generic;
using System.Text.Json.Serialization;
2020-04-21 09:12:17 +00:00
using Flow.Launcher.Plugin;
using System.Text.Json;
2014-07-05 15:10:34 +00:00
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Core.Plugin
2014-07-05 15:10:34 +00:00
{
2022-09-01 02:34:47 +00:00
public record JsonRPCBase(int Id, JsonRPCErrorModel Error = default);
public record JsonRPCErrorModel(int Code, string Message, string Data);
2014-07-07 15:05:06 +00:00
2022-09-01 02:34:47 +00:00
public record JsonRPCResponseModel(int Id, JsonRPCErrorModel Error = default) : JsonRPCBase(Id, Error);
public record JsonRPCQueryResponseModel(int Id,
[property: JsonPropertyName("result")] List<JsonRPCResult> Result,
IReadOnlyDictionary<string, object> SettingsChange = null,
2022-09-01 02:34:47 +00:00
string DebugMessage = "",
JsonRPCErrorModel Error = default) : JsonRPCResponseModel(Id, Error);
2021-02-14 05:59:59 +00:00
2022-09-01 02:34:47 +00:00
public record JsonRPCRequestModel(int Id,
string Method,
object[] Parameters,
IReadOnlyDictionary<string, object> Settings = default,
2022-09-01 02:34:47 +00:00
JsonRPCErrorModel Error = default) : JsonRPCBase(Id, Error);
2014-07-18 12:00:55 +00:00
/// <summary>
2020-04-22 10:26:09 +00:00
/// Json RPC Request(in query response) that client sent to Flow Launcher
2014-07-18 12:00:55 +00:00
/// </summary>
2022-09-01 02:34:47 +00:00
public record JsonRPCClientRequestModel(
int Id,
string Method,
object[] Parameters,
IReadOnlyDictionary<string, object> Settings,
2022-09-01 02:34:47 +00:00
bool DontHideAfterAction = false,
JsonRPCErrorModel Error = default) : JsonRPCRequestModel(Id, Method, Parameters, Settings, Error);
2014-07-18 12:00:55 +00:00
/// <summary>
2020-04-22 10:26:09 +00:00
/// Represent the json-rpc result item that client send to Flow Launcher
2014-07-18 12:00:55 +00:00
/// Typically, we will send back this request model to client after user select the result item
2020-04-22 10:26:09 +00:00
/// But if the request method starts with "Flow Launcher.", we will invoke the public APIs we expose.
2014-07-18 12:00:55 +00:00
/// </summary>
2014-07-07 15:05:06 +00:00
public class JsonRPCResult : Result
{
2014-07-18 12:00:55 +00:00
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
2021-11-14 05:48:53 +00:00
public Dictionary<string, object> SettingsChange { get; set; }
2014-07-05 15:10:34 +00:00
}
2022-08-08 00:50:52 +00:00
}