Skip to content

Commit c7cee4a

Browse files
committed
add ensure latest installation
1 parent c013713 commit c7cee4a

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

Flow.Launcher.Core/ExternalPlugins/PluginEnvironment.cs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Droplex;
22
using Flow.Launcher.Core.Plugin;
3-
using Flow.Launcher.Infrastructure;
43
using Flow.Launcher.Infrastructure.Logger;
54
using Flow.Launcher.Infrastructure.UserSettings;
65
using Flow.Launcher.Plugin;
@@ -15,13 +14,23 @@ namespace Flow.Launcher.Core.ExternalPlugins
1514
{
1615
public class PluginEnvironment
1716
{
18-
private const string PythonExecutable = "pythonw.exe";
19-
20-
private const string NodeExecutable = "node.exe";
17+
private const string environments = "Environments";
2118

22-
private const string PythonEnv = "Python";
19+
private const string python = "Python";
2320

24-
private const string NodeEnv = "Node.js";
21+
private static string pythonEnvDirPath = Path.Combine(DataLocation.DataDirectory(), environments, python);
22+
23+
private static string pythonDirPath = Path.Combine(pythonEnvDirPath, "PythonEmbeddable-v3.8.9");
24+
25+
private string pythonFilePath = Path.Combine(pythonDirPath, "pythonw.exe");
26+
27+
private const string nodejs = "Node.js";
28+
29+
private static string nodeEnvDirPath = Path.Combine(DataLocation.DataDirectory(), environments, nodejs);
30+
31+
private static string nodeDirPath = Path.Combine(nodeEnvDirPath, "Node-v16.18.0");
32+
33+
private string nodeFilePath = Path.Combine(nodeDirPath, $"node-v16.18.0-win-x64\\node.exe");
2534

2635
private List<PluginMetadata> pluginMetadataList;
2736

@@ -35,17 +44,17 @@ internal PluginEnvironment(List<PluginMetadata> pluginMetadataList, PluginsSetti
3544
//TODO: CHECK IF NEED TO RESET PATH AFTER FLOW UPDATE
3645
internal IEnumerable<PluginPair> PythonSetup()
3746
{
38-
return Setup(AllowedLanguage.Python, PythonEnv);
47+
return Setup(AllowedLanguage.Python, python);
3948
}
4049

4150
internal IEnumerable<PluginPair> TypeScriptSetup()
4251
{
43-
return Setup(AllowedLanguage.TypeScript, NodeEnv);
52+
return Setup(AllowedLanguage.TypeScript, nodejs);
4453
}
4554

4655
internal IEnumerable<PluginPair> JavaScriptSetup()
4756
{
48-
return Setup(AllowedLanguage.JavaScript, NodeEnv);
57+
return Setup(AllowedLanguage.JavaScript, nodejs);
4958
}
5059

5160
private IEnumerable<PluginPair> Setup(string languageType, string environment)
@@ -59,13 +68,31 @@ private IEnumerable<PluginPair> Setup(string languageType, string environment)
5968
{
6069
case AllowedLanguage.Python:
6170
if (!string.IsNullOrEmpty(pluginSettings.PythonFilePath) && FilesFolders.FileExists(pluginSettings.PythonFilePath))
71+
{
72+
EnsureLatestInstalled(
73+
pythonFilePath,
74+
pluginSettings.PythonFilePath,
75+
pythonEnvDirPath,
76+
languageType);
77+
6278
return SetPathForPluginPairs(pluginSettings.PythonFilePath, languageType);
79+
}
80+
6381
break;
6482

6583
case AllowedLanguage.TypeScript:
6684
case AllowedLanguage.JavaScript:
6785
if (!string.IsNullOrEmpty(pluginSettings.NodeFilePath) && FilesFolders.FileExists(pluginSettings.NodeFilePath))
86+
{
87+
EnsureLatestInstalled(
88+
nodeFilePath,
89+
pluginSettings.NodeFilePath,
90+
nodeEnvDirPath,
91+
languageType);
92+
6893
return SetPathForPluginPairs(pluginSettings.NodeFilePath, languageType);
94+
}
95+
6996
break;
7097

7198
default:
@@ -134,35 +161,42 @@ private IEnumerable<PluginPair> Setup(string languageType, string environment)
134161

135162
private void InstallEnvironment(string languageType)
136163
{
137-
var environments = "Environments";
138-
139164
switch (languageType)
140165
{
141166
case AllowedLanguage.Python:
142-
var pythonDirPath = Path.Combine(DataLocation.DataDirectory(), environments, "PythonEmbeddable");
143167
FilesFolders.RemoveFolderIfExists(pythonDirPath);
144168

145169
// Python 3.8.9 is used for Windows 7 compatibility
146170
DroplexPackage.Drop(App.python_3_8_9_embeddable, pythonDirPath).Wait();
147171

148-
pluginSettings.PythonFilePath = Path.Combine(pythonDirPath, PythonExecutable);
172+
pluginSettings.PythonFilePath = pythonFilePath;
149173
break;
150174

151175
case AllowedLanguage.TypeScript:
152176
case AllowedLanguage.JavaScript:
153-
var nodeDirPath = Path.Combine(DataLocation.DataDirectory(), environments, "Node");
154177
FilesFolders.RemoveFolderIfExists(nodeDirPath);
155178

156179
DroplexPackage.Drop(App.nodejs_16_18_0, nodeDirPath).Wait();
157180

158-
pluginSettings.NodeFilePath = Path.Combine(nodeDirPath, $"node-v16.18.0-win-x64\\{NodeExecutable}");
181+
pluginSettings.NodeFilePath = nodeFilePath;
159182
break;
160183

161184
default:
162185
break;
163186
}
164187
}
165188

189+
private void EnsureLatestInstalled(string expectedPath, string currentPath, string installedDirPath, string languagType)
190+
{
191+
if (expectedPath == currentPath)
192+
return;
193+
194+
FilesFolders.RemoveFolderIfExists(installedDirPath);
195+
196+
InstallEnvironment(languagType);
197+
198+
}
199+
166200
private IEnumerable<PluginPair> SetPathForPluginPairs(string filePath, string languageToSet)
167201
{
168202
var pluginPairs = new List<PluginPair>();

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using TextBox = System.Windows.Controls.TextBox;
2929
using ThemeManager = ModernWpf.ThemeManager;
3030
using OpenFileDialog = System.Windows.Forms.OpenFileDialog;
31+
using Flow.Launcher.Core.ExternalPlugins;
3132

3233
namespace Flow.Launcher
3334
{

0 commit comments

Comments
 (0)