mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #556 from taooceros/JsonCaseInsensitive
JsonRPC camelCase and Case Insensitive
This commit is contained in:
commit
dd2f84a42f
3 changed files with 22 additions and 16 deletions
|
|
@ -30,12 +30,8 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
public string Data { get; set; }
|
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; }
|
public string Result { get; set; }
|
||||||
|
|
||||||
|
|
@ -50,17 +46,19 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
public string DebugMessage { get; set; }
|
public string DebugMessage { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class JsonRPCRequestModel : JsonRPCModelBase
|
public class JsonRPCRequestModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("method")]
|
|
||||||
public string Method { get; set; }
|
public string Method { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("parameters")]
|
|
||||||
public object[] Parameters { get; set; }
|
public object[] Parameters { get; set; }
|
||||||
|
|
||||||
|
private static readonly JsonSerializerOptions options = new()
|
||||||
|
{
|
||||||
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||||
|
};
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return JsonSerializer.Serialize(this);
|
return JsonSerializer.Serialize(this, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +75,6 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JsonRPCClientRequestModel : JsonRPCRequestModel
|
public class JsonRPCClientRequestModel : JsonRPCRequestModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("dontHideAfterAction")]
|
|
||||||
public bool DontHideAfterAction { get; set; }
|
public bool DontHideAfterAction { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,10 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly JsonSerializerOptions _options = new()
|
private static readonly JsonSerializerOptions options = new()
|
||||||
{
|
{
|
||||||
|
PropertyNameCaseInsensitive = true,
|
||||||
|
IgnoreNullValues = true,
|
||||||
Converters =
|
Converters =
|
||||||
{
|
{
|
||||||
new JsonObjectConverter()
|
new JsonObjectConverter()
|
||||||
|
|
@ -60,7 +62,9 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
if (output == Stream.Null) return null;
|
if (output == Stream.Null) return null;
|
||||||
|
|
||||||
var queryResponseModel = await
|
var queryResponseModel = await
|
||||||
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, _options);
|
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, options);
|
||||||
|
|
||||||
|
await output.DisposeAsync();
|
||||||
|
|
||||||
return ParseResults(queryResponseModel);
|
return ParseResults(queryResponseModel);
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +74,7 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
if (string.IsNullOrEmpty(output)) return null;
|
if (string.IsNullOrEmpty(output)) return null;
|
||||||
|
|
||||||
var queryResponseModel =
|
var queryResponseModel =
|
||||||
JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output, _options);
|
JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output, options);
|
||||||
return ParseResults(queryResponseModel);
|
return ParseResults(queryResponseModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +114,7 @@ namespace Flow.Launcher.Core.Plugin
|
||||||
return !result.JsonRPCAction.DontHideAfterAction;
|
return !result.JsonRPCAction.DontHideAfterAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, _options);
|
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, options);
|
||||||
|
|
||||||
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
|
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ namespace Flow.Launcher.Storage
|
||||||
|
|
||||||
private static int GenerateStaticHashCode(string s, int start = HASH_INITIAL)
|
private static int GenerateStaticHashCode(string s, int start = HASH_INITIAL)
|
||||||
{
|
{
|
||||||
|
if (s == null)
|
||||||
|
{
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
// skip the empty space
|
// skip the empty space
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue