From be8abafddaf6d5d0f1494dfafa246ecb9848d1bb Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Thu, 10 Jun 2021 13:06:35 +0800 Subject: [PATCH] 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 f684bc6aa..ff9c11a94 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -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> DeserializedResultAsync(Stream output) { @@ -88,10 +94,10 @@ namespace Flow.Launcher.Core.Plugin { 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 @@ namespace Flow.Launcher.Core.Plugin { 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 @@ namespace Flow.Launcher.Core.Plugin 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; }