From aa3e7decd80e12c5c6e1add5e311237b4a4aa0f2 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Thu, 10 Jun 2021 11:21:58 +0800 Subject: [PATCH 1/3] Fix Don'tHideAfterAction logic for JsonRPCPlugin.cs --- Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index 875f4fb3ea1..f684bc6aa9b 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -84,27 +84,34 @@ private List ParseResults(JsonRPCQueryResponseModel queryResponseModel) { 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[14..], + 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 + + JsonRPCRequestModel jsonRpcRequestModel = + JsonSerializer.Deserialize(actionResponse); + + if (jsonRpcRequestModel != null + && !string.IsNullOrEmpty(jsonRpcRequestModel.Method) + && jsonRpcRequestModel.Method.StartsWith("Flow.Launcher.")) { - 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.Substring(4), + jsonRpcRequestModel.Parameters); } } From be8abafddaf6d5d0f1494dfafa246ecb9848d1bb Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Thu, 10 Jun 2021 13:06:35 +0800 Subject: [PATCH 2/3] fix another hardcode issue, and the JsonSerialization problem --- Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index f684bc6aa9b..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) { @@ -88,10 +94,10 @@ private List ParseResults(JsonRPCQueryResponseModel queryResponseModel) { return !result.JsonRPCAction.DontHideAfterAction; } - + if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher.")) { - ExecuteFlowLauncherAPI(result.JsonRPCAction.Method[14..], + ExecuteFlowLauncherAPI(result.JsonRPCAction.Method["Flow.Launcher.".Length..], result.JsonRPCAction.Parameters); } else @@ -102,15 +108,12 @@ private List ParseResults(JsonRPCQueryResponseModel queryResponseModel) { return !result.JsonRPCAction.DontHideAfterAction; } - - JsonRPCRequestModel jsonRpcRequestModel = - JsonSerializer.Deserialize(actionResponse); - - if (jsonRpcRequestModel != null - && !string.IsNullOrEmpty(jsonRpcRequestModel.Method) - && jsonRpcRequestModel.Method.StartsWith("Flow.Launcher.")) + + var jsonRpcRequestModel = JsonSerializer.Deserialize(actionResponse, _options); + + if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false) { - ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method.Substring(4), + ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method["Flow.Launcher.".Length..], jsonRpcRequestModel.Parameters); } } @@ -188,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; } From 5cedf7084ce5cd2c3cbe975155579d8d562656e6 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Thu, 10 Jun 2021 15:08:10 +0800 Subject: [PATCH 3/3] Remove Unused Code --- Flow.Launcher.Core/Plugin/JsonPRCModel.cs | 38 ++--------------------- 1 file changed, 3 insertions(+), 35 deletions(-) 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