Skip to content

Commit 0fcceae

Browse files
authored
Merge pull request #469 from taooceros/FixHideLogic
Fix hide logic
2 parents a5f5c09 + 5cedf70 commit 0fcceae

File tree

2 files changed

+35
-54
lines changed

2 files changed

+35
-54
lines changed

Flow.Launcher.Core/Plugin/JsonPRCModel.cs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
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,
32
* 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
43
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
54
*
@@ -62,37 +61,6 @@ public class JsonRPCRequestModel : JsonRPCModelBase
6261
public override string ToString()
6362
{
6463
return JsonSerializer.Serialize(this);
65-
66-
string rpc = string.Empty;
67-
if (Parameters != null && Parameters.Length > 0)
68-
{
69-
string parameters = $"[{string.Join(',', Parameters.Select(GetParameterByType))}]";
70-
rpc = $@"{{\""method\"":\""{Method}\"",\""parameters\"":{parameters}";
71-
}
72-
else
73-
{
74-
rpc = $@"{{\""method\"":\""{Method}\"",\""parameters\"":[]";
75-
}
76-
77-
return rpc;
78-
79-
}
80-
81-
private string GetParameterByType(object parameter)
82-
=> parameter switch
83-
{
84-
null => "null",
85-
string p => $@"\""{ReplaceEscapes(p)}\""",
86-
bool p => $@"{p.ToString().ToLower()}",
87-
_ => $@"\""{ReplaceEscapes(parameter.ToString())}\"""
88-
};
89-
90-
91-
private string ReplaceEscapes(string str)
92-
{
93-
return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo
94-
.Replace(@"\", @"\\") //Escapes itself when passed to client
95-
.Replace(@"""", @"\\""""");
9664
}
9765
}
9866

@@ -101,7 +69,7 @@ private string ReplaceEscapes(string str)
10169
/// </summary>
10270
public class JsonRPCServerRequestModel : JsonRPCRequestModel
10371
{
104-
72+
10573
}
10674

10775
/// <summary>
@@ -122,4 +90,4 @@ public class JsonRPCResult : Result
12290
{
12391
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
12492
}
125-
}
93+
}

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 32 additions & 19 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
{
@@ -84,27 +90,31 @@ private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
8490
{
8591
if (result.JsonRPCAction == null) return false;
8692

87-
if (!string.IsNullOrEmpty(result.JsonRPCAction.Method))
93+
if (string.IsNullOrEmpty(result.JsonRPCAction.Method))
94+
{
95+
return !result.JsonRPCAction.DontHideAfterAction;
96+
}
97+
98+
if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher."))
8899
{
89-
if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher."))
100+
ExecuteFlowLauncherAPI(result.JsonRPCAction.Method["Flow.Launcher.".Length..],
101+
result.JsonRPCAction.Parameters);
102+
}
103+
else
104+
{
105+
var actionResponse = ExecuteCallback(result.JsonRPCAction);
106+
107+
if (string.IsNullOrEmpty(actionResponse))
90108
{
91-
ExecuteFlowLauncherAPI(result.JsonRPCAction.Method[14..],
92-
result.JsonRPCAction.Parameters);
109+
return !result.JsonRPCAction.DontHideAfterAction;
93110
}
94-
else
111+
112+
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, _options);
113+
114+
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
95115
{
96-
string actionReponse = ExecuteCallback(result.JsonRPCAction);
97-
if (string.IsNullOrEmpty(actionReponse))
98-
return false;
99-
JsonRPCRequestModel jsonRpcRequestModel =
100-
JsonSerializer.Deserialize<JsonRPCRequestModel>(actionReponse);
101-
if (jsonRpcRequestModel != null
102-
&& !string.IsNullOrEmpty(jsonRpcRequestModel.Method)
103-
&& jsonRpcRequestModel.Method.StartsWith("Flow.Launcher."))
104-
{
105-
ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method.Substring(4),
106-
jsonRpcRequestModel.Parameters);
107-
}
116+
ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method["Flow.Launcher.".Length..],
117+
jsonRpcRequestModel.Parameters);
108118
}
109119
}
110120

@@ -181,7 +191,10 @@ protected string Execute(ProcessStartInfo startInfo)
181191

182192
if (result.StartsWith("DEBUG:"))
183193
{
184-
MessageBox.Show(new Form {TopMost = true}, result.Substring(6));
194+
MessageBox.Show(new Form
195+
{
196+
TopMost = true
197+
}, result.Substring(6));
185198
return string.Empty;
186199
}
187200

0 commit comments

Comments
 (0)