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
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2021-06-08 00:02:25 +00:00
|
|
|
|
using Flow.Launcher.Core.Resource;
|
2014-07-18 12:00:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-07-10 15:57:08 +00:00
|
|
|
|
using System.Linq;
|
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
|
|
|
|
{
|
2014-07-07 15:05:06 +00:00
|
|
|
|
public class JsonRPCErrorModel
|
2014-07-05 15:10:34 +00:00
|
|
|
|
{
|
2014-07-07 15:05:06 +00:00
|
|
|
|
public int Code { get; set; }
|
2014-07-05 15:10:34 +00:00
|
|
|
|
|
2014-07-07 15:05:06 +00:00
|
|
|
|
public string Message { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public string Data { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class JsonRPCModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class JsonRPCResponseModel : JsonRPCModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Result { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public JsonRPCErrorModel Error { get; set; }
|
2014-07-05 15:10:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-07 15:05:06 +00:00
|
|
|
|
public class JsonRPCQueryResponseModel : JsonRPCResponseModel
|
2014-07-05 15:10:34 +00:00
|
|
|
|
{
|
2021-02-03 09:50:36 +00:00
|
|
|
|
[JsonPropertyName("result")]
|
2014-07-09 10:15:23 +00:00
|
|
|
|
public new List<JsonRPCResult> Result { get; set; }
|
2021-02-14 05:59:59 +00:00
|
|
|
|
|
|
|
|
|
|
public string DebugMessage { get; set; }
|
2014-07-07 15:05:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-18 15:12:50 +00:00
|
|
|
|
public class JsonRPCRequestModel : JsonRPCModelBase
|
2014-07-07 15:05:06 +00:00
|
|
|
|
{
|
2021-06-04 03:08:40 +00:00
|
|
|
|
[JsonPropertyName("method")]
|
2014-07-07 15:05:06 +00:00
|
|
|
|
public string Method { get; set; }
|
|
|
|
|
|
|
2021-06-04 03:08:40 +00:00
|
|
|
|
[JsonPropertyName("parameters")]
|
2014-07-10 15:57:08 +00:00
|
|
|
|
public object[] Parameters { get; set; }
|
|
|
|
|
|
|
2014-07-09 10:15:23 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
2021-06-07 05:03:59 +00:00
|
|
|
|
return JsonSerializer.Serialize(this);
|
2015-03-03 10:29:36 +00:00
|
|
|
|
}
|
2014-07-07 15:05:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-18 12:00:55 +00:00
|
|
|
|
/// <summary>
|
2020-04-22 10:26:09 +00:00
|
|
|
|
/// Json RPC Request that Flow Launcher sent to client
|
2014-07-18 12:00:55 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class JsonRPCServerRequestModel : JsonRPCRequestModel
|
|
|
|
|
|
{
|
2021-06-10 07:08:10 +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>
|
|
|
|
|
|
public class JsonRPCClientRequestModel : JsonRPCRequestModel
|
|
|
|
|
|
{
|
2021-06-08 00:02:25 +00:00
|
|
|
|
[JsonPropertyName("dontHideAfterAction")]
|
2014-07-18 12:00:55 +00:00
|
|
|
|
public bool DontHideAfterAction { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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; }
|
2014-07-05 15:10:34 +00:00
|
|
|
|
}
|
2021-06-10 07:08:10 +00:00
|
|
|
|
}
|