From 824ea07ab2ca46c6563563708371f1af2d2a7f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Sun, 14 Feb 2021 13:59:59 +0800 Subject: [PATCH] add Debug message field for debugging --- Flow.Launcher.Core/Plugin/JsonPRCModel.cs | 2 + Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 43 ++++++++++++---------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs index a0731f8fb..b1c8ff6ea 100644 --- a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs +++ b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs @@ -45,6 +45,8 @@ namespace Flow.Launcher.Core.Plugin { [JsonPropertyName("result")] public new List Result { get; set; } + + public string DebugMessage { get; set; } } public class JsonRPCRequestModel : JsonRPCModelBase diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index a5633b118..e342a5f94 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -48,11 +48,35 @@ namespace Flow.Launcher.Core.Plugin + private async Task> DeserializedResultAsync(Stream output) + { + if (output == Stream.Null) return null; + + JsonRPCQueryResponseModel queryResponseModel = await + JsonSerializer.DeserializeAsync(output); + + return ParseResults(queryResponseModel); + } + + private List DeserializedResult(string output) + { + if (string.IsNullOrEmpty(output)) return null; + + JsonRPCQueryResponseModel queryResponseModel = + JsonSerializer.Deserialize(output); + return ParseResults(queryResponseModel); + } + private List ParseResults(JsonRPCQueryResponseModel queryResponseModel) { var results = new List(); if (queryResponseModel.Result == null) return null; + if(!string.IsNullOrEmpty(queryResponseModel.DebugMessage)) + { + context.API.ShowMsg(queryResponseModel.DebugMessage); + } + foreach (JsonRPCResult result in queryResponseModel.Result) { result.Action = c => @@ -89,25 +113,6 @@ namespace Flow.Launcher.Core.Plugin return results; } - private async Task> DeserializedResultAsync(Stream output) - { - if (output == Stream.Null) return null; - - JsonRPCQueryResponseModel queryResponseModel = await - JsonSerializer.DeserializeAsync(output); - - return ParseResults(queryResponseModel); - } - - private List DeserializedResult(string output) - { - if (string.IsNullOrEmpty(output)) return null; - - JsonRPCQueryResponseModel queryResponseModel = - JsonSerializer.Deserialize(output); - return ParseResults(queryResponseModel); - } - private void ExecuteFlowLauncherAPI(string method, object[] parameters) { MethodInfo methodInfo = PluginManager.API.GetType().GetMethod(method);