Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Flow.Launcher.Core/Plugin/ExecutablePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Core.Plugin
Expand All @@ -21,17 +24,17 @@ public ExecutablePlugin(string filename)
};
}

protected override string ExecuteQuery(Query query)
protected override Task<Stream> ExecuteQueryAsync(Query query, CancellationToken token)
{
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
{
Method = "query",
Parameters = new object[] { query.Search },
Parameters = new object[] {query.Search},
};

_startInfo.Arguments = $"\"{request}\"";

return Execute(_startInfo);
return ExecuteAsync(_startInfo, token);
}

protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
Expand All @@ -40,10 +43,12 @@ protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
return Execute(_startInfo);
}

protected override string ExecuteContextMenu(Result selectedResult) {
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel {
protected override string ExecuteContextMenu(Result selectedResult)
{
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
{
Method = "contextmenu",
Parameters = new object[] { selectedResult.ContextData },
Parameters = new object[] {selectedResult.ContextData},
};

_startInfo.Arguments = $"\"{request}\"";
Expand Down
35 changes: 13 additions & 22 deletions Flow.Launcher.Core/Plugin/JsonPRCModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class JsonRPCQueryResponseModel : JsonRPCResponseModel
{
[JsonPropertyName("result")]
public new List<JsonRPCResult> Result { get; set; }

public string DebugMessage { get; set; }
}

public class JsonRPCRequestModel : JsonRPCModelBase
Expand All @@ -58,40 +60,29 @@ public override string ToString()
string rpc = string.Empty;
if (Parameters != null && Parameters.Length > 0)
{
string parameters = Parameters.Aggregate("[", (current, o) => current + (GetParameterByType(o) + ","));
parameters = parameters.Substring(0, parameters.Length - 1) + "]";
rpc = string.Format(@"{{\""method\"":\""{0}\"",\""parameters\"":{1}", Method, parameters);
string parameters = $"[{string.Join(',', Parameters.Select(GetParameterByType))}]";
rpc = $@"{{\""method\"":\""{Method}\"",\""parameters\"":{parameters}";
}
else
{
rpc = string.Format(@"{{\""method\"":\""{0}\"",\""parameters\"":[]", Method);
rpc = $@"{{\""method\"":\""{Method}\"",\""parameters\"":[]";
}

return rpc;

}

private string GetParameterByType(object parameter)
=> parameter switch
{
if (parameter == null) {
return "null";
}
if (parameter is string)
{
return string.Format(@"\""{0}\""", ReplaceEscapes(parameter.ToString()));
}
if (parameter is int || parameter is float || parameter is double)
{
return string.Format(@"{0}", parameter);
}
if (parameter is bool)
{
return string.Format(@"{0}", parameter.ToString().ToLower());
}
return parameter.ToString();
}
null => "null",
string _ => $@"\""{ReplaceEscapes(parameter.ToString())}\""",
bool _ => $@"{parameter.ToString().ToLower()}",
_ => parameter.ToString()
};


private string ReplaceEscapes(string str)
private string ReplaceEscapes(string str)
{
return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo
.Replace(@"\", @"\\") //Escapes itself when passed to client
Expand Down
Loading