Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement JSONRPC V2 #1353

Merged
merged 29 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
67d1b89
Implement JSONRPC V2 Draft
taooceros Sep 1, 2022
094da0e
Rollback rename
taooceros Sep 1, 2022
2fd13c0
Rollback rename
taooceros Sep 1, 2022
85fdcde
Merge branch 'dev' of github.com:Flow-Launcher/Flow.Launcher into jso…
taooceros Mar 26, 2023
16dcdf0
load v2 plugins
taooceros Mar 26, 2023
683f6eb
refactor jsonrpc structure (extract setting to a standalone file Port…
taooceros Mar 26, 2023
a3367ab
fix some bug (v1 still broken)
taooceros Mar 26, 2023
b425aac
fix a little bit more
taooceros Mar 26, 2023
1551567
fix v1
taooceros Mar 26, 2023
e183920
implement v2
taooceros Jun 2, 2023
8093a7c
Merge remote-tracking branch 'origin/dev' into jsonrpc_v2
taooceros Jun 2, 2023
f691259
Merge branch 'dev' into jsonrpc_v2
taooceros Jun 23, 2023
32bbf1e
Finally make JSONRPC Bidirection work
taooceros Jun 24, 2023
cb6fb80
Change abstract back to normal class for JsonRPCExecuteResponse.cs; C…
taooceros Jun 25, 2023
b57804f
Merge branch 'dev' into jsonrpc_v2
taooceros Jun 25, 2023
a971156
Add Initialization Code
taooceros Jun 25, 2023
83a6110
fix error stream issue
taooceros Jul 3, 2023
0459d6e
fix v1 plugin issue
taooceros Jul 3, 2023
e1deefc
Add UpdateResults Functionality
taooceros Jul 3, 2023
c50d98c
Abstract out ProcessStreamPluginV2.cs and add ExecutablePluginV2.cs
taooceros Jul 3, 2023
24c125f
Merge remote-tracking branch 'origin/dev' into jsonrpc_v2
taooceros Jul 3, 2023
9dacfb1
Merge remote-tracking branch 'origin/dev' into jsonrpc_v2
jjw24 Aug 7, 2023
29aefee
remove irrelevant comment
jjw24 Aug 22, 2023
20f23b0
update streamjsonrpc and use systemtextjsonformatter
taooceros Aug 28, 2023
c67d0fa
remove obsolete comment
jjw24 Sep 11, 2023
3c2ea38
Merge branch 'dev' of https://github.com/Flow-Launcher/Flow.Launcher …
taooceros Oct 31, 2023
1c63cd9
remove duplicate comment summary
taooceros Oct 31, 2023
f5b1b4f
rename and add js/ts v2
taooceros Nov 4, 2023
0700910
Merge branch 'dev' into jsonrpc_v2
taooceros Nov 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal IEnumerable<PluginPair> Setup()
string.Empty, MessageBoxButtons.YesNo) == DialogResult.No)
{
var msg = $"Please select the {EnvName} executable";
var selectedFile = string.Empty;
string selectedFile;

selectedFile = GetFileFromDialog(msg, FileDialogFilter);

Expand Down Expand Up @@ -131,14 +131,8 @@ private string GetFileFromDialog(string title, string filter = "")
};

var result = dlg.ShowDialog();
if (result == DialogResult.OK)
{
return dlg.FileName;
}
else
{
return string.Empty;
}
return result == DialogResult.OK ? dlg.FileName : string.Empty;

}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Core.ExternalPlugins.Environments
{

internal class JavaScriptV2Environment : TypeScriptV2Environment
{
internal override string Language => AllowedLanguage.JavaScriptV2;

internal JavaScriptV2Environment(List<PluginMetadata> pluginMetadataList, PluginsSettings pluginSettings) : base(pluginMetadataList, pluginSettings) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Core.ExternalPlugins.Environments
{
internal class PythonV2Environment : PythonEnvironment
{
internal override string Language => AllowedLanguage.PythonV2;

internal override PluginPair CreatePluginPair(string filePath, PluginMetadata metadata)
{
return new PluginPair
{
Plugin = new PythonPluginV2(filePath),
Metadata = metadata
};
}

internal PythonV2Environment(List<PluginMetadata> pluginMetadataList, PluginsSettings pluginSettings) : base(pluginMetadataList, pluginSettings) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Generic;
using Droplex;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Plugin;
using System.IO;
using Flow.Launcher.Core.Plugin;

namespace Flow.Launcher.Core.ExternalPlugins.Environments
{
internal class TypeScriptV2Environment : AbstractPluginEnvironment
{
internal override string Language => AllowedLanguage.TypeScriptV2;

internal override string EnvName => DataLocation.NodeEnvironmentName;

internal override string EnvPath => Path.Combine(DataLocation.PluginEnvironmentsPath, EnvName);

internal override string InstallPath => Path.Combine(EnvPath, "Node-v16.18.0");
internal override string ExecutablePath => Path.Combine(InstallPath, "node-v16.18.0-win-x64\\node.exe");

internal override string PluginsSettingsFilePath { get => PluginSettings.NodeExecutablePath; set => PluginSettings.NodeExecutablePath = value; }

internal TypeScriptV2Environment(List<PluginMetadata> pluginMetadataList, PluginsSettings pluginSettings) : base(pluginMetadataList, pluginSettings) { }

internal override void InstallEnvironment()
{
FilesFolders.RemoveFolderIfExists(InstallPath);

DroplexPackage.Drop(App.nodejs_16_18_0, InstallPath).Wait();

PluginsSettingsFilePath = ExecutablePath;
}

internal override PluginPair CreatePluginPair(string filePath, PluginMetadata metadata)
{
return new PluginPair
{
Plugin = new NodePluginV2(filePath),
Metadata = metadata
};
}
}
}
2 changes: 1 addition & 1 deletion Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Logger;
using System;
using System.Collections.Generic;
using System.Threading;
Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher.Core/Flow.Launcher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<PackageReference Include="FSharp.Core" Version="7.0.400" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
<PackageReference Include="squirrel.windows" Version="1.5.2" NoWarn="NU1701" />
<PackageReference Include="StreamJsonRpc" Version="2.16.36" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions Flow.Launcher.Core/Plugin/ExecutablePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -27,14 +28,14 @@ public ExecutablePlugin(string filename)
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
{
// since this is not static, request strings will build up in ArgumentList if index is not specified
_startInfo.ArgumentList[0] = request.ToString();
_startInfo.ArgumentList[0] = JsonSerializer.Serialize(request, RequestSerializeOption);
return ExecuteAsync(_startInfo, token);
}

protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
{
// since this is not static, request strings will build up in ArgumentList if index is not specified
_startInfo.ArgumentList[0] = rpcRequest.ToString();
_startInfo.ArgumentList[0] = JsonSerializer.Serialize(rpcRequest, RequestSerializeOption);
jjw24 marked this conversation as resolved.
Show resolved Hide resolved
return Execute(_startInfo);
}
}
Expand Down
26 changes: 26 additions & 0 deletions Flow.Launcher.Core/Plugin/ExecutablePluginV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

namespace Flow.Launcher.Core.Plugin
{
internal sealed class ExecutablePluginV2 : ProcessStreamPluginV2
{
protected override ProcessStartInfo StartInfo { get; set; }

public ExecutablePluginV2(string filename)
{
StartInfo = new ProcessStartInfo
{
FileName = filename,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
}

}
}
76 changes: 22 additions & 54 deletions Flow.Launcher.Core/Plugin/JsonPRCModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,35 @@

namespace Flow.Launcher.Core.Plugin
{
public class JsonRPCErrorModel
{
public int Code { get; set; }

public string Message { get; set; }

public string Data { get; set; }
}


public class JsonRPCResponseModel
{
public string Result { get; set; }
public record JsonRPCBase(int Id, JsonRPCErrorModel Error = default);
public record JsonRPCErrorModel(int Code, string Message, string Data);

public JsonRPCErrorModel Error { get; set; }
}

public class JsonRPCQueryResponseModel : JsonRPCResponseModel
{
[JsonPropertyName("result")]
public new List<JsonRPCResult> Result { get; set; }
public record JsonRPCResponseModel(int Id, JsonRPCErrorModel Error = default) : JsonRPCBase(Id, Error);
public record JsonRPCQueryResponseModel(int Id,
[property: JsonPropertyName("result")] List<JsonRPCResult> Result,
IReadOnlyDictionary<string, object> SettingsChanges = null,
string DebugMessage = "",
JsonRPCErrorModel Error = default) : JsonRPCResponseModel(Id, Error);

public Dictionary<string, object> SettingsChange { get; set; }
public record JsonRPCRequestModel(int Id,
string Method,
object[] Parameters,
IReadOnlyDictionary<string, object> Settings = default,
JsonRPCErrorModel Error = default) : JsonRPCBase(Id, Error);

public string DebugMessage { get; set; }
}

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

public object[] Parameters { get; set; }

public Dictionary<string, object> Settings { get; set; }

private static readonly JsonSerializerOptions options = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
public override string ToString()
{
return JsonSerializer.Serialize(this, options);
}
}

/// <summary>
/// Json RPC Request that Flow Launcher sent to client
/// </summary>
public class JsonRPCServerRequestModel : JsonRPCRequestModel
{

}

/// <summary>
/// Json RPC Request(in query response) that client sent to Flow Launcher
/// </summary>
public class JsonRPCClientRequestModel : JsonRPCRequestModel
{
public bool DontHideAfterAction { get; set; }
}

public record JsonRPCClientRequestModel(
int Id,
string Method,
object[] Parameters,
IReadOnlyDictionary<string, object> Settings,
bool DontHideAfterAction = false,
JsonRPCErrorModel Error = default) : JsonRPCRequestModel(Id, Method, Parameters, Settings, Error);


/// <summary>
/// Represent the json-rpc result item that client send to Flow Launcher
/// Typically, we will send back this request model to client after user select the result item
Expand Down
Loading
Loading