Skip to content

Commit aeba056

Browse files
authored
Merge pull request #363 from Flow-Launcher/dev
Release 1.8.0 | Plugin 2.0.0
2 parents 65f7745 + 770f3ef commit aeba056

File tree

225 files changed

+3511
-1910
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+3511
-1910
lines changed
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.

Flow.Launcher.Core/Flow.Launcher.Core.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0-windows</TargetFramework>
55
<UseWpf>true</UseWpf>
66
<UseWindowsForms>true</UseWindowsForms>
77
<OutputType>Library</OutputType>
@@ -16,7 +16,7 @@
1616

1717
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1818
<DebugSymbols>true</DebugSymbols>
19-
<DebugType>full</DebugType>
19+
<DebugType>portable</DebugType>
2020
<Optimize>false</Optimize>
2121
<OutputPath>..\Output\Debug\</OutputPath>
2222
<DefineConstants>DEBUG;TRACE</DefineConstants>
@@ -53,14 +53,11 @@
5353
</ItemGroup>
5454

5555
<ItemGroup>
56+
<PackageReference Include="Droplex" Version="1.3.1" />
5657
<PackageReference Include="FSharp.Core" Version="4.7.1" />
5758
<PackageReference Include="squirrel.windows" Version="1.5.2" />
5859
</ItemGroup>
5960

60-
<ItemGroup>
61-
<Folder Include="Properties\" />
62-
</ItemGroup>
63-
6461
<ItemGroup>
6562
<ProjectReference Include="..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
6663
<ProjectReference Include="..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />

Flow.Launcher.Core/Plugin/ExecutablePlugin.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
22
using System.Diagnostics;
3+
using System.IO;
4+
using System.Threading;
5+
using System.Threading.Tasks;
36
using Flow.Launcher.Plugin;
47

58
namespace Flow.Launcher.Core.Plugin
@@ -21,17 +24,17 @@ public ExecutablePlugin(string filename)
2124
};
2225
}
2326

24-
protected override string ExecuteQuery(Query query)
27+
protected override Task<Stream> ExecuteQueryAsync(Query query, CancellationToken token)
2528
{
2629
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
2730
{
2831
Method = "query",
29-
Parameters = new object[] { query.Search },
32+
Parameters = new object[] {query.Search},
3033
};
3134

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

34-
return Execute(_startInfo);
37+
return ExecuteAsync(_startInfo, token);
3538
}
3639

3740
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
@@ -40,10 +43,12 @@ protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
4043
return Execute(_startInfo);
4144
}
4245

43-
protected override string ExecuteContextMenu(Result selectedResult) {
44-
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel {
46+
protected override string ExecuteContextMenu(Result selectedResult)
47+
{
48+
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
49+
{
4550
Method = "contextmenu",
46-
Parameters = new object[] { selectedResult.ContextData },
51+
Parameters = new object[] {selectedResult.ContextData},
4752
};
4853

4954
_startInfo.Arguments = $"\"{request}\"";
Lines changed: 15 additions & 62 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
*
@@ -13,10 +12,12 @@
1312
*
1413
*/
1514

15+
using Flow.Launcher.Core.Resource;
1616
using System.Collections.Generic;
1717
using System.Linq;
1818
using System.Text.Json.Serialization;
1919
using Flow.Launcher.Plugin;
20+
using System.Text.Json;
2021

2122
namespace Flow.Launcher.Core.Plugin
2223
{
@@ -29,12 +30,8 @@ public class JsonRPCErrorModel
2930
public string Data { get; set; }
3031
}
3132

32-
public class JsonRPCModelBase
33-
{
34-
public int Id { get; set; }
35-
}
3633

37-
public class JsonRPCResponseModel : JsonRPCModelBase
34+
public class JsonRPCResponseModel
3835
{
3936
public string Result { get; set; }
4037

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

50-
public class JsonRPCRequestModel : JsonRPCModelBase
46+
public string DebugMessage { get; set; }
47+
}
48+
49+
public class JsonRPCRequestModel
5150
{
5251
public string Method { get; set; }
5352

5453
public object[] Parameters { get; set; }
5554

56-
public override string ToString()
55+
private static readonly JsonSerializerOptions options = new()
5756
{
58-
string rpc = string.Empty;
59-
if (Parameters != null && Parameters.Length > 0)
60-
{
61-
string parameters = Parameters.Aggregate("[", (current, o) => current + (GetParameterByType(o) + ","));
62-
parameters = parameters.Substring(0, parameters.Length - 1) + "]";
63-
rpc = string.Format(@"{{\""method\"":\""{0}\"",\""parameters\"":{1}", Method, parameters);
64-
}
65-
else
66-
{
67-
rpc = string.Format(@"{{\""method\"":\""{0}\"",\""parameters\"":[]", Method);
68-
}
69-
70-
return rpc;
71-
72-
}
73-
74-
private string GetParameterByType(object parameter)
75-
{
76-
if (parameter == null) {
77-
return "null";
78-
}
79-
if (parameter is string)
80-
{
81-
return string.Format(@"\""{0}\""", ReplaceEscapes(parameter.ToString()));
82-
}
83-
if (parameter is int || parameter is float || parameter is double)
84-
{
85-
return string.Format(@"{0}", parameter);
86-
}
87-
if (parameter is bool)
88-
{
89-
return string.Format(@"{0}", parameter.ToString().ToLower());
90-
}
91-
return parameter.ToString();
92-
}
93-
94-
private string ReplaceEscapes(string str)
57+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
58+
};
59+
public override string ToString()
9560
{
96-
return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo
97-
.Replace(@"\", @"\\") //Escapes itself when passed to client
98-
.Replace(@"""", @"\\""""");
61+
return JsonSerializer.Serialize(this, options);
9962
}
10063
}
10164

@@ -104,11 +67,7 @@ private string ReplaceEscapes(string str)
10467
/// </summary>
10568
public class JsonRPCServerRequestModel : JsonRPCRequestModel
10669
{
107-
public override string ToString()
108-
{
109-
string rpc = base.ToString();
110-
return rpc + "}";
111-
}
70+
11271
}
11372

11473
/// <summary>
@@ -117,12 +76,6 @@ public override string ToString()
11776
public class JsonRPCClientRequestModel : JsonRPCRequestModel
11877
{
11978
public bool DontHideAfterAction { get; set; }
120-
121-
public override string ToString()
122-
{
123-
string rpc = base.ToString();
124-
return rpc + "}";
125-
}
12679
}
12780

12881
/// <summary>
@@ -134,4 +87,4 @@ public class JsonRPCResult : Result
13487
{
13588
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
13689
}
137-
}
90+
}

0 commit comments

Comments
 (0)