mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
commit
0fcceaef9d
2 changed files with 35 additions and 54 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
|
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Flow Launcher and other plugins,
|
||||||
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Flow Launcher and other plugins,
|
|
||||||
* 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
|
* 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.
|
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
|
||||||
*
|
*
|
||||||
|
|
@ -62,37 +61,6 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return JsonSerializer.Serialize(this);
|
return JsonSerializer.Serialize(this);
|
||||||
|
|
||||||
string rpc = string.Empty;
|
|
||||||
if (Parameters != null && Parameters.Length > 0)
|
|
||||||
{
|
|
||||||
string parameters = $"[{string.Join(',', Parameters.Select(GetParameterByType))}]";
|
|
||||||
rpc = $@"{{\""method\"":\""{Method}\"",\""parameters\"":{parameters}";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rpc = $@"{{\""method\"":\""{Method}\"",\""parameters\"":[]";
|
|
||||||
}
|
|
||||||
|
|
||||||
return rpc;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetParameterByType(object parameter)
|
|
||||||
=> parameter switch
|
|
||||||
{
|
|
||||||
null => "null",
|
|
||||||
string p => $@"\""{ReplaceEscapes(p)}\""",
|
|
||||||
bool p => $@"{p.ToString().ToLower()}",
|
|
||||||
_ => $@"\""{ReplaceEscapes(parameter.ToString())}\"""
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private string ReplaceEscapes(string str)
|
|
||||||
{
|
|
||||||
return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo
|
|
||||||
.Replace(@"\", @"\\") //Escapes itself when passed to client
|
|
||||||
.Replace(@"""", @"\\""""");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +69,7 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JsonRPCServerRequestModel : JsonRPCRequestModel
|
public class JsonRPCServerRequestModel : JsonRPCRequestModel
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -122,4 +90,4 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
{
|
{
|
||||||
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
|
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,13 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly JsonSerializerOptions _options = new() {Converters = {new JsonObjectConverter()}};
|
private static readonly JsonSerializerOptions _options = new()
|
||||||
|
{
|
||||||
|
Converters =
|
||||||
|
{
|
||||||
|
new JsonObjectConverter()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private async Task<List<Result>> DeserializedResultAsync(Stream output)
|
private async Task<List<Result>> DeserializedResultAsync(Stream output)
|
||||||
{
|
{
|
||||||
|
|
@ -84,27 +90,31 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
{
|
{
|
||||||
if (result.JsonRPCAction == null) return false;
|
if (result.JsonRPCAction == null) return false;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(result.JsonRPCAction.Method))
|
if (string.IsNullOrEmpty(result.JsonRPCAction.Method))
|
||||||
{
|
{
|
||||||
if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher."))
|
return !result.JsonRPCAction.DontHideAfterAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher."))
|
||||||
|
{
|
||||||
|
ExecuteFlowLauncherAPI(result.JsonRPCAction.Method["Flow.Launcher.".Length..],
|
||||||
|
result.JsonRPCAction.Parameters);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var actionResponse = ExecuteCallback(result.JsonRPCAction);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(actionResponse))
|
||||||
{
|
{
|
||||||
ExecuteFlowLauncherAPI(result.JsonRPCAction.Method[14..],
|
return !result.JsonRPCAction.DontHideAfterAction;
|
||||||
result.JsonRPCAction.Parameters);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, _options);
|
||||||
|
|
||||||
|
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
|
||||||
{
|
{
|
||||||
string actionReponse = ExecuteCallback(result.JsonRPCAction);
|
ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method["Flow.Launcher.".Length..],
|
||||||
if (string.IsNullOrEmpty(actionReponse))
|
jsonRpcRequestModel.Parameters);
|
||||||
return false;
|
|
||||||
JsonRPCRequestModel jsonRpcRequestModel =
|
|
||||||
JsonSerializer.Deserialize<JsonRPCRequestModel>(actionReponse);
|
|
||||||
if (jsonRpcRequestModel != null
|
|
||||||
&& !string.IsNullOrEmpty(jsonRpcRequestModel.Method)
|
|
||||||
&& jsonRpcRequestModel.Method.StartsWith("Flow.Launcher."))
|
|
||||||
{
|
|
||||||
ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method.Substring(4),
|
|
||||||
jsonRpcRequestModel.Parameters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,7 +191,10 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
|
|
||||||
if (result.StartsWith("DEBUG:"))
|
if (result.StartsWith("DEBUG:"))
|
||||||
{
|
{
|
||||||
MessageBox.Show(new Form {TopMost = true}, result.Substring(6));
|
MessageBox.Show(new Form
|
||||||
|
{
|
||||||
|
TopMost = true
|
||||||
|
}, result.Substring(6));
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue