diff --git a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs index 2b3bd61b039..5232e46daee 100644 --- a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs +++ b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs @@ -30,12 +30,8 @@ public class JsonRPCErrorModel public string Data { get; set; } } - public class JsonRPCModelBase - { - public int Id { get; set; } - } - public class JsonRPCResponseModel : JsonRPCModelBase + public class JsonRPCResponseModel { public string Result { get; set; } @@ -49,18 +45,20 @@ public class JsonRPCQueryResponseModel : JsonRPCResponseModel public string DebugMessage { get; set; } } - - public class JsonRPCRequestModel : JsonRPCModelBase + + public class JsonRPCRequestModel { - [JsonPropertyName("method")] public string Method { get; set; } - [JsonPropertyName("parameters")] public object[] Parameters { get; set; } + private static readonly JsonSerializerOptions options = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; public override string ToString() { - return JsonSerializer.Serialize(this); + return JsonSerializer.Serialize(this, options); } } @@ -77,7 +75,6 @@ public class JsonRPCServerRequestModel : JsonRPCRequestModel /// public class JsonRPCClientRequestModel : JsonRPCRequestModel { - [JsonPropertyName("dontHideAfterAction")] public bool DontHideAfterAction { get; set; } } diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index 65f8fc608d6..431458881ec 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -47,8 +47,10 @@ public List LoadContextMenus(Result selectedResult) } } - private static readonly JsonSerializerOptions _options = new() + private static readonly JsonSerializerOptions options = new() { + PropertyNameCaseInsensitive = true, + IgnoreNullValues = true, Converters = { new JsonObjectConverter() @@ -60,8 +62,10 @@ private async Task> DeserializedResultAsync(Stream output) if (output == Stream.Null) return null; var queryResponseModel = await - JsonSerializer.DeserializeAsync(output, _options); + JsonSerializer.DeserializeAsync(output, options); + await output.DisposeAsync(); + return ParseResults(queryResponseModel); } @@ -70,7 +74,7 @@ private List DeserializedResult(string output) if (string.IsNullOrEmpty(output)) return null; var queryResponseModel = - JsonSerializer.Deserialize(output, _options); + JsonSerializer.Deserialize(output, options); return ParseResults(queryResponseModel); } @@ -110,7 +114,7 @@ private List ParseResults(JsonRPCQueryResponseModel queryResponseModel) return !result.JsonRPCAction.DontHideAfterAction; } - var jsonRpcRequestModel = JsonSerializer.Deserialize(actionResponse, _options); + var jsonRpcRequestModel = JsonSerializer.Deserialize(actionResponse, options); if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false) { diff --git a/Flow.Launcher/Storage/UserSelectedRecord.cs b/Flow.Launcher/Storage/UserSelectedRecord.cs index 8d8956cfa4e..23d8c4fafd4 100644 --- a/Flow.Launcher/Storage/UserSelectedRecord.cs +++ b/Flow.Launcher/Storage/UserSelectedRecord.cs @@ -28,6 +28,11 @@ public UserSelectedRecord() private static int GenerateStaticHashCode(string s, int start = HASH_INITIAL) { + if (s == null) + { + return start; + } + unchecked { // skip the empty space @@ -101,4 +106,4 @@ public int GetSelectedCount(Result result) return selectedCount; } } -} +} \ No newline at end of file