Skip to content

Commit be8abaf

Browse files
committed
fix another hardcode issue, and the JsonSerialization problem
1 parent aa3e7de commit be8abaf

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ public List<Result> LoadContextMenus(Result selectedResult)
4646
}
4747
}
4848

49-
private static readonly JsonSerializerOptions _options = new() {Converters = {new JsonObjectConverter()}};
49+
private static readonly JsonSerializerOptions _options = new()
50+
{
51+
Converters =
52+
{
53+
new JsonObjectConverter()
54+
}
55+
};
5056

5157
private async Task<List<Result>> DeserializedResultAsync(Stream output)
5258
{
@@ -88,10 +94,10 @@ private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
8894
{
8995
return !result.JsonRPCAction.DontHideAfterAction;
9096
}
91-
97+
9298
if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher."))
9399
{
94-
ExecuteFlowLauncherAPI(result.JsonRPCAction.Method[14..],
100+
ExecuteFlowLauncherAPI(result.JsonRPCAction.Method["Flow.Launcher.".Length..],
95101
result.JsonRPCAction.Parameters);
96102
}
97103
else
@@ -102,15 +108,12 @@ private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
102108
{
103109
return !result.JsonRPCAction.DontHideAfterAction;
104110
}
105-
106-
JsonRPCRequestModel jsonRpcRequestModel =
107-
JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse);
108-
109-
if (jsonRpcRequestModel != null
110-
&& !string.IsNullOrEmpty(jsonRpcRequestModel.Method)
111-
&& jsonRpcRequestModel.Method.StartsWith("Flow.Launcher."))
111+
112+
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, _options);
113+
114+
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
112115
{
113-
ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method.Substring(4),
116+
ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method["Flow.Launcher.".Length..],
114117
jsonRpcRequestModel.Parameters);
115118
}
116119
}
@@ -188,7 +191,10 @@ protected string Execute(ProcessStartInfo startInfo)
188191

189192
if (result.StartsWith("DEBUG:"))
190193
{
191-
MessageBox.Show(new Form {TopMost = true}, result.Substring(6));
194+
MessageBox.Show(new Form
195+
{
196+
TopMost = true
197+
}, result.Substring(6));
192198
return string.Empty;
193199
}
194200

0 commit comments

Comments
 (0)