1
-
2
- /* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Flow Launcher and other plugins,
1
+ /* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Flow Launcher and other plugins,
3
2
* like python or other self-execute program. But, we added addtional infos (proxy and so on) into rpc request. Also, we didn't use the
4
3
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
5
4
*
13
12
*
14
13
*/
15
14
15
+ using Flow . Launcher . Core . Resource ;
16
16
using System . Collections . Generic ;
17
17
using System . Linq ;
18
18
using System . Text . Json . Serialization ;
19
19
using Flow . Launcher . Plugin ;
20
+ using System . Text . Json ;
20
21
21
22
namespace Flow . Launcher . Core . Plugin
22
23
{
@@ -29,12 +30,8 @@ public class JsonRPCErrorModel
29
30
public string Data { get ; set ; }
30
31
}
31
32
32
- public class JsonRPCModelBase
33
- {
34
- public int Id { get ; set ; }
35
- }
36
33
37
- public class JsonRPCResponseModel : JsonRPCModelBase
34
+ public class JsonRPCResponseModel
38
35
{
39
36
public string Result { get ; set ; }
40
37
@@ -48,45 +45,20 @@ public class JsonRPCQueryResponseModel : JsonRPCResponseModel
48
45
49
46
public string DebugMessage { get ; set ; }
50
47
}
51
-
52
- public class JsonRPCRequestModel : JsonRPCModelBase
48
+
49
+ public class JsonRPCRequestModel
53
50
{
54
51
public string Method { get ; set ; }
55
52
56
53
public object [ ] Parameters { get ; set ; }
57
54
58
- public override string ToString ( )
59
- {
60
- string rpc = string . Empty ;
61
- if ( Parameters != null && Parameters . Length > 0 )
62
- {
63
- string parameters = $ "[{ string . Join ( ',' , Parameters . Select ( GetParameterByType ) ) } ]";
64
- rpc = $@ "{{\""method\"":\""{ Method } \"",\""parameters\"":{ parameters } ";
65
- }
66
- else
67
- {
68
- rpc = $@ "{{\""method\"":\""{ Method } \"",\""parameters\"":[]";
69
- }
70
-
71
- return rpc ;
72
-
73
- }
74
-
75
- private string GetParameterByType ( object parameter )
76
- => parameter switch
55
+ private static readonly JsonSerializerOptions options = new ( )
77
56
{
78
- null => "null" ,
79
- string _ => $@ "\""{ ReplaceEscapes ( parameter . ToString ( ) ) } \""",
80
- bool _ => $@ "{ parameter . ToString ( ) . ToLower ( ) } ",
81
- _ => parameter . ToString ( )
57
+ PropertyNamingPolicy = JsonNamingPolicy . CamelCase
82
58
} ;
83
-
84
-
85
- private string ReplaceEscapes ( string str )
59
+ public override string ToString ( )
86
60
{
87
- return str . Replace ( @"\" , @"\\" ) //Escapes in ProcessStartInfo
88
- . Replace ( @"\" , @"\\" ) //Escapes itself when passed to client
89
- . Replace ( @"""" , @"\\""""" ) ;
61
+ return JsonSerializer . Serialize ( this , options ) ;
90
62
}
91
63
}
92
64
@@ -95,11 +67,7 @@ private string ReplaceEscapes(string str)
95
67
/// </summary>
96
68
public class JsonRPCServerRequestModel : JsonRPCRequestModel
97
69
{
98
- public override string ToString ( )
99
- {
100
- string rpc = base . ToString ( ) ;
101
- return rpc + "}" ;
102
- }
70
+
103
71
}
104
72
105
73
/// <summary>
@@ -108,12 +76,6 @@ public override string ToString()
108
76
public class JsonRPCClientRequestModel : JsonRPCRequestModel
109
77
{
110
78
public bool DontHideAfterAction { get ; set ; }
111
-
112
- public override string ToString ( )
113
- {
114
- string rpc = base . ToString ( ) ;
115
- return rpc + "}" ;
116
- }
117
79
}
118
80
119
81
/// <summary>
@@ -125,4 +87,4 @@ public class JsonRPCResult : Result
125
87
{
126
88
public JsonRPCClientRequestModel JsonRPCAction { get ; set ; }
127
89
}
128
- }
90
+ }
0 commit comments