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;
|
2021-02-03 09:50:36 +00:00
|
|
|
|
using System.Text.Json.Serialization;
|
2020-04-21 09:12:17 +00:00
|
|
|
|
using Flow.Launcher.Plugin;
|
2021-06-07 05:03:59 +00:00
|
|
|
|
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,
|
2023-11-19 14:11:27 +00:00
|
|
|
|
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,
|
2023-03-26 07:24:31 +00:00
|
|
|
|
IReadOnlyDictionary<string, object> Settings = default,
|
2022-09-01 02:34:47 +00:00
|
|
|
|
JsonRPCErrorModel Error = default) : JsonRPCBase(Id, Error);
|
2021-11-14 05:11:05 +00:00
|
|
|
|
|
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,
|
2023-03-26 07:24:31 +00:00
|
|
|
|
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
|
|
|
|
}
|