Merge pull request #469 from taooceros/FixHideLogic

Fix hide logic
This commit is contained in:
Jeremy Wu 2021-06-13 16:05:18 +10:00 committed by GitHub
commit 0fcceaef9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 54 deletions

View file

@ -1,5 +1,4 @@

/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Flow Launcher and other plugins,
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Flow Launcher and other plugins,
* 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
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
*
@ -62,37 +61,6 @@ namespace Flow.Launcher.Core.Plugin
public override string ToString()
{
return JsonSerializer.Serialize(this);
string rpc = string.Empty;
if (Parameters != null && Parameters.Length > 0)
{
string parameters = $"[{string.Join(',', Parameters.Select(GetParameterByType))}]";
rpc = $@"{{\""method\"":\""{Method}\"",\""parameters\"":{parameters}";
}
else
{
rpc = $@"{{\""method\"":\""{Method}\"",\""parameters\"":[]";
}
return rpc;
}
private string GetParameterByType(object parameter)
=> parameter switch
{
null => "null",
string p => $@"\""{ReplaceEscapes(p)}\""",
bool p => $@"{p.ToString().ToLower()}",
_ => $@"\""{ReplaceEscapes(parameter.ToString())}\"""
};
private string ReplaceEscapes(string str)
{
return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo
.Replace(@"\", @"\\") //Escapes itself when passed to client
.Replace(@"""", @"\\""""");
}
}
@ -101,7 +69,7 @@ namespace Flow.Launcher.Core.Plugin
/// </summary>
public class JsonRPCServerRequestModel : JsonRPCRequestModel
{
}
/// <summary>
@ -122,4 +90,4 @@ namespace Flow.Launcher.Core.Plugin
{
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
}
}
}

View file

@ -46,7 +46,13 @@ namespace Flow.Launcher.Core.Plugin
}
}
private static readonly JsonSerializerOptions _options = new() {Converters = {new JsonObjectConverter()}};
private static readonly JsonSerializerOptions _options = new()
{
Converters =
{
new JsonObjectConverter()
}
};
private async Task<List<Result>> DeserializedResultAsync(Stream output)
{
@ -84,27 +90,31 @@ namespace Flow.Launcher.Core.Plugin
{
if (result.JsonRPCAction == null) return false;
if (!string.IsNullOrEmpty(result.JsonRPCAction.Method))
if (string.IsNullOrEmpty(result.JsonRPCAction.Method))
{
if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher."))
return !result.JsonRPCAction.DontHideAfterAction;
}
if (result.JsonRPCAction.Method.StartsWith("Flow.Launcher."))
{
ExecuteFlowLauncherAPI(result.JsonRPCAction.Method["Flow.Launcher.".Length..],
result.JsonRPCAction.Parameters);
}
else
{
var actionResponse = ExecuteCallback(result.JsonRPCAction);
if (string.IsNullOrEmpty(actionResponse))
{
ExecuteFlowLauncherAPI(result.JsonRPCAction.Method[14..],
result.JsonRPCAction.Parameters);
return !result.JsonRPCAction.DontHideAfterAction;
}
else
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, _options);
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
{
string actionReponse = ExecuteCallback(result.JsonRPCAction);
if (string.IsNullOrEmpty(actionReponse))
return false;
JsonRPCRequestModel jsonRpcRequestModel =
JsonSerializer.Deserialize<JsonRPCRequestModel>(actionReponse);
if (jsonRpcRequestModel != null
&& !string.IsNullOrEmpty(jsonRpcRequestModel.Method)
&& jsonRpcRequestModel.Method.StartsWith("Flow.Launcher."))
{
ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method.Substring(4),
jsonRpcRequestModel.Parameters);
}
ExecuteFlowLauncherAPI(jsonRpcRequestModel.Method["Flow.Launcher.".Length..],
jsonRpcRequestModel.Parameters);
}
}
@ -181,7 +191,10 @@ namespace Flow.Launcher.Core.Plugin
if (result.StartsWith("DEBUG:"))
{
MessageBox.Show(new Form {TopMost = true}, result.Substring(6));
MessageBox.Show(new Form
{
TopMost = true
}, result.Substring(6));
return string.Empty;
}