1
1
using Droplex ;
2
2
using Flow . Launcher . Core . Plugin ;
3
- using Flow . Launcher . Infrastructure ;
4
3
using Flow . Launcher . Infrastructure . Logger ;
5
4
using Flow . Launcher . Infrastructure . UserSettings ;
6
5
using Flow . Launcher . Plugin ;
@@ -15,13 +14,23 @@ namespace Flow.Launcher.Core.ExternalPlugins
15
14
{
16
15
public class PluginEnvironment
17
16
{
18
- private const string PythonExecutable = "pythonw.exe" ;
19
-
20
- private const string NodeExecutable = "node.exe" ;
17
+ private const string environments = "Environments" ;
21
18
22
- private const string PythonEnv = "Python" ;
19
+ private const string python = "Python" ;
23
20
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") ;
25
34
26
35
private List < PluginMetadata > pluginMetadataList ;
27
36
@@ -35,17 +44,17 @@ internal PluginEnvironment(List<PluginMetadata> pluginMetadataList, PluginsSetti
35
44
//TODO: CHECK IF NEED TO RESET PATH AFTER FLOW UPDATE
36
45
internal IEnumerable < PluginPair > PythonSetup ( )
37
46
{
38
- return Setup ( AllowedLanguage . Python , PythonEnv ) ;
47
+ return Setup ( AllowedLanguage . Python , python ) ;
39
48
}
40
49
41
50
internal IEnumerable < PluginPair > TypeScriptSetup ( )
42
51
{
43
- return Setup ( AllowedLanguage . TypeScript , NodeEnv ) ;
52
+ return Setup ( AllowedLanguage . TypeScript , nodejs ) ;
44
53
}
45
54
46
55
internal IEnumerable < PluginPair > JavaScriptSetup ( )
47
56
{
48
- return Setup ( AllowedLanguage . JavaScript , NodeEnv ) ;
57
+ return Setup ( AllowedLanguage . JavaScript , nodejs ) ;
49
58
}
50
59
51
60
private IEnumerable < PluginPair > Setup ( string languageType , string environment )
@@ -59,13 +68,31 @@ private IEnumerable<PluginPair> Setup(string languageType, string environment)
59
68
{
60
69
case AllowedLanguage . Python :
61
70
if ( ! string . IsNullOrEmpty ( pluginSettings . PythonFilePath ) && FilesFolders . FileExists ( pluginSettings . PythonFilePath ) )
71
+ {
72
+ EnsureLatestInstalled (
73
+ pythonFilePath ,
74
+ pluginSettings . PythonFilePath ,
75
+ pythonEnvDirPath ,
76
+ languageType ) ;
77
+
62
78
return SetPathForPluginPairs ( pluginSettings . PythonFilePath , languageType ) ;
79
+ }
80
+
63
81
break ;
64
82
65
83
case AllowedLanguage . TypeScript :
66
84
case AllowedLanguage . JavaScript :
67
85
if ( ! string . IsNullOrEmpty ( pluginSettings . NodeFilePath ) && FilesFolders . FileExists ( pluginSettings . NodeFilePath ) )
86
+ {
87
+ EnsureLatestInstalled (
88
+ nodeFilePath ,
89
+ pluginSettings . NodeFilePath ,
90
+ nodeEnvDirPath ,
91
+ languageType ) ;
92
+
68
93
return SetPathForPluginPairs ( pluginSettings . NodeFilePath , languageType ) ;
94
+ }
95
+
69
96
break ;
70
97
71
98
default :
@@ -134,35 +161,42 @@ private IEnumerable<PluginPair> Setup(string languageType, string environment)
134
161
135
162
private void InstallEnvironment ( string languageType )
136
163
{
137
- var environments = "Environments" ;
138
-
139
164
switch ( languageType )
140
165
{
141
166
case AllowedLanguage . Python :
142
- var pythonDirPath = Path . Combine ( DataLocation . DataDirectory ( ) , environments , "PythonEmbeddable" ) ;
143
167
FilesFolders . RemoveFolderIfExists ( pythonDirPath ) ;
144
168
145
169
// Python 3.8.9 is used for Windows 7 compatibility
146
170
DroplexPackage . Drop ( App . python_3_8_9_embeddable , pythonDirPath ) . Wait ( ) ;
147
171
148
- pluginSettings . PythonFilePath = Path . Combine ( pythonDirPath , PythonExecutable ) ;
172
+ pluginSettings . PythonFilePath = pythonFilePath ;
149
173
break ;
150
174
151
175
case AllowedLanguage . TypeScript :
152
176
case AllowedLanguage . JavaScript :
153
- var nodeDirPath = Path . Combine ( DataLocation . DataDirectory ( ) , environments , "Node" ) ;
154
177
FilesFolders . RemoveFolderIfExists ( nodeDirPath ) ;
155
178
156
179
DroplexPackage . Drop ( App . nodejs_16_18_0 , nodeDirPath ) . Wait ( ) ;
157
180
158
- pluginSettings . NodeFilePath = Path . Combine ( nodeDirPath , $ "node-v16.18.0-win-x64 \\ { NodeExecutable } " ) ;
181
+ pluginSettings . NodeFilePath = nodeFilePath ;
159
182
break ;
160
183
161
184
default :
162
185
break ;
163
186
}
164
187
}
165
188
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
+
166
200
private IEnumerable < PluginPair > SetPathForPluginPairs ( string filePath , string languageToSet )
167
201
{
168
202
var pluginPairs = new List < PluginPair > ( ) ;
0 commit comments