Skip to content

Commit dd2f84a

Browse files
authored
Merge pull request #556 from taooceros/JsonCaseInsensitive
JsonRPC camelCase and Case Insensitive
2 parents f82042a + b3c6466 commit dd2f84a

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

Flow.Launcher.Core/Plugin/JsonPRCModel.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ public class JsonRPCErrorModel
3030
public string Data { get; set; }
3131
}
3232

33-
public class JsonRPCModelBase
34-
{
35-
public int Id { get; set; }
36-
}
3733

38-
public class JsonRPCResponseModel : JsonRPCModelBase
34+
public class JsonRPCResponseModel
3935
{
4036
public string Result { get; set; }
4137

@@ -49,18 +45,20 @@ public class JsonRPCQueryResponseModel : JsonRPCResponseModel
4945

5046
public string DebugMessage { get; set; }
5147
}
52-
53-
public class JsonRPCRequestModel : JsonRPCModelBase
48+
49+
public class JsonRPCRequestModel
5450
{
55-
[JsonPropertyName("method")]
5651
public string Method { get; set; }
5752

58-
[JsonPropertyName("parameters")]
5953
public object[] Parameters { get; set; }
6054

55+
private static readonly JsonSerializerOptions options = new()
56+
{
57+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
58+
};
6159
public override string ToString()
6260
{
63-
return JsonSerializer.Serialize(this);
61+
return JsonSerializer.Serialize(this, options);
6462
}
6563
}
6664

@@ -77,7 +75,6 @@ public class JsonRPCServerRequestModel : JsonRPCRequestModel
7775
/// </summary>
7876
public class JsonRPCClientRequestModel : JsonRPCRequestModel
7977
{
80-
[JsonPropertyName("dontHideAfterAction")]
8178
public bool DontHideAfterAction { get; set; }
8279
}
8380

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ public List<Result> LoadContextMenus(Result selectedResult)
4747
}
4848
}
4949

50-
private static readonly JsonSerializerOptions _options = new()
50+
private static readonly JsonSerializerOptions options = new()
5151
{
52+
PropertyNameCaseInsensitive = true,
53+
IgnoreNullValues = true,
5254
Converters =
5355
{
5456
new JsonObjectConverter()
@@ -60,8 +62,10 @@ private async Task<List<Result>> DeserializedResultAsync(Stream output)
6062
if (output == Stream.Null) return null;
6163

6264
var queryResponseModel = await
63-
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, _options);
65+
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, options);
6466

67+
await output.DisposeAsync();
68+
6569
return ParseResults(queryResponseModel);
6670
}
6771

@@ -70,7 +74,7 @@ private List<Result> DeserializedResult(string output)
7074
if (string.IsNullOrEmpty(output)) return null;
7175

7276
var queryResponseModel =
73-
JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output, _options);
77+
JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output, options);
7478
return ParseResults(queryResponseModel);
7579
}
7680

@@ -110,7 +114,7 @@ private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
110114
return !result.JsonRPCAction.DontHideAfterAction;
111115
}
112116

113-
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, _options);
117+
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, options);
114118

115119
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
116120
{

Flow.Launcher/Storage/UserSelectedRecord.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public UserSelectedRecord()
2828

2929
private static int GenerateStaticHashCode(string s, int start = HASH_INITIAL)
3030
{
31+
if (s == null)
32+
{
33+
return start;
34+
}
35+
3136
unchecked
3237
{
3338
// skip the empty space
@@ -101,4 +106,4 @@ public int GetSelectedCount(Result result)
101106
return selectedCount;
102107
}
103108
}
104-
}
109+
}

0 commit comments

Comments
 (0)