Skip to content

Commit

Permalink
Merge pull request #363 from Flow-Launcher/dev
Browse files Browse the repository at this point in the history
Release 1.8.0 | Plugin 2.0.0
  • Loading branch information
jjw24 authored Jul 19, 2021
2 parents 65f7745 + 770f3ef commit aeba056
Show file tree
Hide file tree
Showing 225 changed files with 3,511 additions and 1,910 deletions.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
11 changes: 4 additions & 7 deletions Flow.Launcher.Core/Flow.Launcher.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWpf>true</UseWpf>
<UseWindowsForms>true</UseWindowsForms>
<OutputType>Library</OutputType>
Expand All @@ -16,7 +16,7 @@

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Output\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
Expand Down Expand Up @@ -53,14 +53,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Droplex" Version="1.3.1" />
<PackageReference Include="FSharp.Core" Version="4.7.1" />
<PackageReference Include="squirrel.windows" Version="1.5.2" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
<ProjectReference Include="..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
Expand Down
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
77 changes: 15 additions & 62 deletions Flow.Launcher.Core/Plugin/JsonPRCModel.cs
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -13,10 +12,12 @@
*
*/

using Flow.Launcher.Core.Resource;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin;
using System.Text.Json;

namespace Flow.Launcher.Core.Plugin
{
Expand All @@ -29,12 +30,8 @@ public class JsonRPCErrorModel
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; }

Expand All @@ -45,57 +42,23 @@ public class JsonRPCQueryResponseModel : JsonRPCResponseModel
{
[JsonPropertyName("result")]
public new List<JsonRPCResult> Result { get; set; }
}

public class JsonRPCRequestModel : JsonRPCModelBase
public string DebugMessage { get; set; }
}

public class JsonRPCRequestModel
{
public string Method { get; set; }

public object[] Parameters { get; set; }

public override string ToString()
private static readonly JsonSerializerOptions options = new()
{
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);
}
else
{
rpc = string.Format(@"{{\""method\"":\""{0}\"",\""parameters\"":[]", Method);
}

return rpc;

}

private string GetParameterByType(object parameter)
{
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();
}

private string ReplaceEscapes(string str)
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
public override string ToString()
{
return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo
.Replace(@"\", @"\\") //Escapes itself when passed to client
.Replace(@"""", @"\\""""");
return JsonSerializer.Serialize(this, options);
}
}

Expand All @@ -104,11 +67,7 @@ private string ReplaceEscapes(string str)
/// </summary>
public class JsonRPCServerRequestModel : JsonRPCRequestModel
{
public override string ToString()
{
string rpc = base.ToString();
return rpc + "}";
}

}

/// <summary>
Expand All @@ -117,12 +76,6 @@ public override string ToString()
public class JsonRPCClientRequestModel : JsonRPCRequestModel
{
public bool DontHideAfterAction { get; set; }

public override string ToString()
{
string rpc = base.ToString();
return rpc + "}";
}
}

/// <summary>
Expand All @@ -134,4 +87,4 @@ public class JsonRPCResult : Result
{
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
}
}
}
Loading

0 comments on commit aeba056

Please sign in to comment.