diff --git a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs index 1dac4e25db3..2b3bd61b039 100644 --- a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs +++ b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs @@ -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 * "id" and "jsonrpc" in the request, since it's not so useful in our request model. * @@ -62,37 +61,6 @@ public class JsonRPCRequestModel : JsonRPCModelBase public override string ToString() { 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 @@ private string ReplaceEscapes(string str) /// public class JsonRPCServerRequestModel : JsonRPCRequestModel { - + } /// @@ -122,4 +90,4 @@ public class JsonRPCResult : Result { public JsonRPCClientRequestModel JsonRPCAction { get; set; } } -} +} \ No newline at end of file diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index 875f4fb3ea1..ff9c11a9405 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -46,7 +46,13 @@ public List LoadContextMenus(Result selectedResult) } } - private static readonly JsonSerializerOptions _options = new() {Converters = {new JsonObjectConverter()}}; + private static readonly JsonSerializerOptions _options = new() + { + Converters = + { + new JsonObjectConverter() + } + }; private async Task> DeserializedResultAsync(Stream output) { @@ -84,27 +90,31 @@ private List ParseResults(JsonRPCQueryResponseModel queryResponseModel) { if (result.JsonRPCAction == null) return false; - if (!string.IsNullOrEmpty(result.JsonRPCAction.Method)) + if (string.IsNullOrEmpty(result.JsonRPCAction.Method)) + { + return !result.JsonRPCAction.DontHideAfterAction; + } + + if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher.")) { - 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..], - result.JsonRPCAction.Parameters); + return !result.JsonRPCAction.DontHideAfterAction; } - else + + var jsonRpcRequestModel = JsonSerializer.Deserialize(actionResponse, _options); + + if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false) { - string actionReponse = ExecuteCallback(result.JsonRPCAction); - if (string.IsNullOrEmpty(actionReponse)) - return false; - JsonRPCRequestModel jsonRpcRequestModel = - JsonSerializer.Deserialize(actionReponse); - if (jsonRpcRequestModel != null - && !string.IsNullOrEmpty(jsonRpcRequestModel.Method) - && jsonRpcRequestModel.Method.StartsWith("Flow.Launcher.")) - { - ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method.Substring(4), - jsonRpcRequestModel.Parameters); - } + ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method["Flow.Launcher.".Length..], + jsonRpcRequestModel.Parameters); } } @@ -181,7 +191,10 @@ protected string Execute(ProcessStartInfo startInfo) 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; }