From eeaa6f920d6d223f97e49db9745354c31dda5ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 3 Feb 2021 17:50:21 +0800 Subject: [PATCH 1/2] add null check before updateresultmanifest --- Flow.Launcher.Core/Plugin/PluginManager.cs | 2 ++ Flow.Launcher/ViewModel/MainViewModel.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 26167e945ac..700a7d509e2 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -183,6 +183,8 @@ public static async Task> QueryForPlugin(PluginPair pair, Query que throw new ArgumentOutOfRangeException(); } token.ThrowIfCancellationRequested(); + if (results == null) + return results; UpdatePluginMetadata(results, metadata, query); metadata.QueryCount += 1; diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 05dbb3a8b8b..afbe6e19758 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -363,7 +363,7 @@ private void QueryContextMenu() } if (!match.IsSearchPrecisionScoreMet()) return false; - + r.Score = match.Score; return true; @@ -512,7 +512,7 @@ async Task QueryTask(PluginPair plugin) await Task.Yield(); var results = await PluginManager.QueryForPlugin(plugin, query, currentCancellationToken); - if (!currentCancellationToken.IsCancellationRequested) + if (!currentCancellationToken.IsCancellationRequested && results != null) _resultsUpdateQueue.Post(new ResultsForUpdate(results, plugin.Metadata, query, currentCancellationToken)); } From d0b94c5b81d0f62f9eef67fc9af97fab7948f6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 3 Feb 2021 17:50:36 +0800 Subject: [PATCH 2/2] specify name for property to avoid property collision --- Flow.Launcher.Core/Plugin/JsonPRCModel.cs | 2 + Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 65 ++++++++++------------ 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs index 9bc7c2472cb..247fe1889d6 100644 --- a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs +++ b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs @@ -15,6 +15,7 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json.Serialization; using Flow.Launcher.Plugin; namespace Flow.Launcher.Core.Plugin @@ -42,6 +43,7 @@ public class JsonRPCResponseModel : JsonRPCModelBase public class JsonRPCQueryResponseModel : JsonRPCResponseModel { + [JsonPropertyName("result")] public new List Result { get; set; } } diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index 3d4522498d9..c7ad70391b7 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -147,47 +147,42 @@ protected string Execute(ProcessStartInfo startInfo) { try { - using (var process = Process.Start(startInfo)) + using var process = Process.Start(startInfo); + if (process == null) { - if (process != null) + Log.Error("|JsonRPCPlugin.Execute|Can't start new process"); + return string.Empty; + } + + using var standardOutput = process.StandardOutput; + var result = standardOutput.ReadToEnd(); + if (string.IsNullOrEmpty(result)) + { + using (var standardError = process.StandardError) { - using (var standardOutput = process.StandardOutput) + var error = standardError.ReadToEnd(); + if (!string.IsNullOrEmpty(error)) { - var result = standardOutput.ReadToEnd(); - if (string.IsNullOrEmpty(result)) - { - using (var standardError = process.StandardError) - { - var error = standardError.ReadToEnd(); - if (!string.IsNullOrEmpty(error)) - { - Log.Error($"|JsonRPCPlugin.Execute|{error}"); - return string.Empty; - } - else - { - Log.Error("|JsonRPCPlugin.Execute|Empty standard output and standard error."); - return string.Empty; - } - } - } - else if (result.StartsWith("DEBUG:")) - { - MessageBox.Show(new Form { TopMost = true }, result.Substring(6)); - return string.Empty; - } - else - { - return result; - } + Log.Error($"|JsonRPCPlugin.Execute|{error}"); + return string.Empty; + } + else + { + Log.Error("|JsonRPCPlugin.Execute|Empty standard output and standard error."); + return string.Empty; } - } - else - { - Log.Error("|JsonRPCPlugin.Execute|Can't start new process"); - return string.Empty; } } + else if (result.StartsWith("DEBUG:")) + { + MessageBox.Show(new Form { TopMost = true }, result.Substring(6)); + return string.Empty; + } + else + { + return result; + } + } catch (Exception e) {