Skip to content

Commit f5b1b4f

Browse files
committed
rename and add js/ts v2
1 parent 1c63cd9 commit f5b1b4f

File tree

11 files changed

+159
-48
lines changed

11 files changed

+159
-48
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
using Flow.Launcher.Infrastructure.UserSettings;
3+
using Flow.Launcher.Plugin;
4+
5+
namespace Flow.Launcher.Core.ExternalPlugins.Environments
6+
{
7+
8+
internal class JavaScriptV2Environment : TypeScriptV2Environment
9+
{
10+
internal override string Language => AllowedLanguage.JavaScriptV2;
11+
12+
internal JavaScriptV2Environment(List<PluginMetadata> pluginMetadataList, PluginsSettings pluginSettings) : base(pluginMetadataList, pluginSettings) { }
13+
}
14+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Collections.Generic;
2+
using Droplex;
3+
using Flow.Launcher.Infrastructure.UserSettings;
4+
using Flow.Launcher.Plugin.SharedCommands;
5+
using Flow.Launcher.Plugin;
6+
using System.IO;
7+
using Flow.Launcher.Core.Plugin;
8+
9+
namespace Flow.Launcher.Core.ExternalPlugins.Environments
10+
{
11+
internal class TypeScriptV2Environment : AbstractPluginEnvironment
12+
{
13+
internal override string Language => AllowedLanguage.TypeScriptV2;
14+
15+
internal override string EnvName => DataLocation.NodeEnvironmentName;
16+
17+
internal override string EnvPath => Path.Combine(DataLocation.PluginEnvironmentsPath, EnvName);
18+
19+
internal override string InstallPath => Path.Combine(EnvPath, "Node-v16.18.0");
20+
internal override string ExecutablePath => Path.Combine(InstallPath, "node-v16.18.0-win-x64\\node.exe");
21+
22+
internal override string PluginsSettingsFilePath { get => PluginSettings.NodeExecutablePath; set => PluginSettings.NodeExecutablePath = value; }
23+
24+
internal TypeScriptV2Environment(List<PluginMetadata> pluginMetadataList, PluginsSettings pluginSettings) : base(pluginMetadataList, pluginSettings) { }
25+
26+
internal override void InstallEnvironment()
27+
{
28+
FilesFolders.RemoveFolderIfExists(InstallPath);
29+
30+
DroplexPackage.Drop(App.nodejs_16_18_0, InstallPath).Wait();
31+
32+
PluginsSettingsFilePath = ExecutablePath;
33+
}
34+
35+
internal override PluginPair CreatePluginPair(string filePath, PluginMetadata metadata)
36+
{
37+
return new PluginPair
38+
{
39+
Plugin = new NodePluginV2(filePath),
40+
Metadata = metadata
41+
};
42+
}
43+
}
44+
}

Flow.Launcher.Core/Plugin/JsonRPCModelContext.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ internal abstract class JsonRPCPluginBase : IAsyncPlugin, IContextMenu, ISetting
6969

7070
protected abstract Task<bool> ExecuteResultAsync(JsonRPCResult result);
7171

72-
protected PortableSettings Settings { get; set; }
72+
protected JsonRPCPluginSettings Settings { get; set; }
7373

7474
protected List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
7575
{
@@ -135,7 +135,7 @@ private async Task InitSettingAsync()
135135
deserializer.Deserialize<JsonRpcConfigurationModel>(
136136
await File.ReadAllTextAsync(SettingConfigurationPath));
137137

138-
Settings ??= new PortableSettings
138+
Settings ??= new JsonRPCPluginSettings
139139
{
140140
Configuration = configuration, SettingPath = SettingPath, API = Context.API
141141
};

Flow.Launcher.Core/Plugin/PortableSettings.cs renamed to Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Flow.Launcher.Core.Plugin
1010
{
11-
public class PortableSettings
11+
public class JsonRPCPluginSettings
1212
{
1313
public required JsonRpcConfigurationModel Configuration { get; init; }
1414

Flow.Launcher.Core/Plugin/NodePlugin.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using System.IO;
3+
using System.Text.Json;
34
using System.Threading;
45
using System.Threading.Tasks;
56
using Flow.Launcher.Plugin;
@@ -27,23 +28,22 @@ public NodePlugin(string filename)
2728

2829
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
2930
{
30-
_startInfo.ArgumentList[1] = request.ToString();
31+
_startInfo.ArgumentList[1] = JsonSerializer.Serialize(request);
3132
return ExecuteAsync(_startInfo, token);
3233
}
3334

3435
protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
3536
{
3637
// since this is not static, request strings will build up in ArgumentList if index is not specified
37-
_startInfo.ArgumentList[1] = rpcRequest.ToString();
38+
_startInfo.ArgumentList[1] = JsonSerializer.Serialize(rpcRequest);
3839
return Execute(_startInfo);
3940
}
4041

4142
public override async Task InitAsync(PluginInitContext context)
4243
{
4344
_startInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
44-
_startInfo.ArgumentList.Add(string.Empty);
45-
await base.InitAsync(context);
4645
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
46+
await base.InitAsync(context);
4747
}
4848
}
4949
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Diagnostics;
2+
using System.IO;
3+
using System.IO.Pipelines;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Flow.Launcher.Plugin;
7+
8+
namespace Flow.Launcher.Core.Plugin
9+
{
10+
/// <summary>
11+
/// Execution of JavaScript & TypeScript plugins
12+
/// </summary>
13+
internal class NodePluginV2 : ProcessStreamPluginV2
14+
{
15+
public NodePluginV2(string filename)
16+
{
17+
StartInfo = new ProcessStartInfo
18+
{
19+
FileName = filename,
20+
UseShellExecute = false,
21+
CreateNoWindow = true,
22+
RedirectStandardOutput = true,
23+
RedirectStandardError = true
24+
};
25+
}
26+
27+
public override string SupportedLanguage { get; set; }
28+
protected override ProcessStartInfo StartInfo { get; set; }
29+
30+
public override async Task InitAsync(PluginInitContext context)
31+
{
32+
StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
33+
StartInfo.ArgumentList.Add(string.Empty);
34+
StartInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
35+
await base.InitAsync(context);
36+
}
37+
}
38+
}

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,33 @@ public static class PluginsLoader
1919
public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
2020
{
2121
var dotnetPlugins = DotNetPlugins(metadatas);
22-
22+
2323
var pythonEnv = new PythonEnvironment(metadatas, settings);
2424
var pythonV2Env = new PythonV2Environment(metadatas, settings);
2525
var tsEnv = new TypeScriptEnvironment(metadatas, settings);
2626
var jsEnv = new JavaScriptEnvironment(metadatas, settings);
27+
var tsV2Env = new TypeScriptV2Environment(metadatas, settings);
28+
var jsV2Env = new JavaScriptV2Environment(metadatas, settings);
2729
var pythonPlugins = pythonEnv.Setup();
2830
var pythonV2Plugins = pythonV2Env.Setup();
2931
var tsPlugins = tsEnv.Setup();
3032
var jsPlugins = jsEnv.Setup();
31-
33+
var tsV2Plugins = tsV2Env.Setup();
34+
var jsV2Plugins = jsV2Env.Setup();
35+
3236
var executablePlugins = ExecutablePlugins(metadatas);
33-
37+
var executableV2Plugins = ExecutableV2Plugins(metadatas);
38+
3439
var plugins = dotnetPlugins
35-
.Concat(pythonPlugins)
36-
.Concat(pythonV2Plugins)
37-
.Concat(tsPlugins)
38-
.Concat(jsPlugins)
39-
.Concat(executablePlugins)
40-
.ToList();
40+
.Concat(pythonPlugins)
41+
.Concat(pythonV2Plugins)
42+
.Concat(tsPlugins)
43+
.Concat(jsPlugins)
44+
.Concat(tsV2Plugins)
45+
.Concat(jsV2Plugins)
46+
.Concat(executablePlugins)
47+
.Concat(executableV2Plugins)
48+
.ToList();
4149
return plugins;
4250
}
4351

@@ -96,7 +104,7 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
96104
return;
97105
}
98106

99-
plugins.Add(new PluginPair {Plugin = plugin, Metadata = metadata});
107+
plugins.Add(new PluginPair { Plugin = plugin, Metadata = metadata });
100108
});
101109
metadata.InitTime += milliseconds;
102110
}
@@ -121,7 +129,7 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
121129
return plugins;
122130
}
123131

124-
public static IEnumerable<PluginPair> ExecutablePlugins(IEnumerable<PluginMetadata> source)
132+
public static IEnumerable<PluginPair> ExecutablePlugins(IEnumerable<PluginMetadata> source)
125133
{
126134
return source
127135
.Where(o => o.Language.Equals(AllowedLanguage.Executable, StringComparison.OrdinalIgnoreCase))
@@ -130,5 +138,15 @@ public static IEnumerable<PluginPair> ExecutablePlugins(IEnumerable<PluginMetada
130138
Plugin = new ExecutablePlugin(metadata.ExecuteFilePath), Metadata = metadata
131139
});
132140
}
141+
142+
public static IEnumerable<PluginPair> ExecutableV2Plugins(IEnumerable<PluginMetadata> source)
143+
{
144+
return source
145+
.Where(o => o.Language.Equals(AllowedLanguage.ExecutableV2, StringComparison.OrdinalIgnoreCase))
146+
.Select(metadata => new PluginPair
147+
{
148+
Plugin = new ExecutablePluginV2(metadata.ExecuteFilePath), Metadata = metadata
149+
});
150+
}
133151
}
134152
}

Flow.Launcher.Core/Plugin/ProcessStreamPluginV2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal abstract class ProcessStreamPluginV2 : JsonRPCPluginV2
1313
{
1414

1515
public override string SupportedLanguage { get; set; }
16-
protected override IDuplexPipe ClientPipe { get; set; }
16+
protected sealed override IDuplexPipe ClientPipe { get; set; }
1717

1818
protected abstract ProcessStartInfo StartInfo { get; set; }
1919

Flow.Launcher.Core/Plugin/PythonPluginV2.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ namespace Flow.Launcher.Core.Plugin
1919
internal sealed class PythonPluginV2 : ProcessStreamPluginV2
2020
{
2121
public override string SupportedLanguage { get; set; } = AllowedLanguage.Python;
22-
23-
protected override IDuplexPipe ClientPipe { get; set; }
2422
protected override ProcessStartInfo StartInfo { get; set; }
2523

2624
public PythonPluginV2(string filename)

0 commit comments

Comments
 (0)