Skip to content

Commit 9eb5489

Browse files
committed
update setting's environment file paths after app update
1 parent 2dba518 commit 9eb5489

File tree

7 files changed

+61
-10
lines changed

7 files changed

+61
-10
lines changed

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ internal abstract class AbstractPluginEnvironment
1414
{
1515
internal abstract string Language { get; }
1616

17-
internal const string Environments = "Environments";
18-
1917
internal abstract string EnvName { get; }
2018

2119
internal abstract string EnvPath { get; }
@@ -37,7 +35,7 @@ internal AbstractPluginEnvironment(List<PluginMetadata> pluginMetadataList, Plug
3735
PluginMetadataList = pluginMetadataList;
3836
PluginSettings = pluginSettings;
3937
}
40-
//TODO: CHECK IF NEED TO RESET PATH AFTER FLOW UPDATE
38+
4139
internal IEnumerable<PluginPair> Setup()
4240
{
4341
if (!PluginMetadataList.Any(o => o.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)))

Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class PythonEnvironment : AbstractPluginEnvironment
1313

1414
internal override string EnvName => "Python";
1515

16-
internal override string EnvPath => Path.Combine(DataLocation.DataDirectory(), Environments, EnvName);
16+
internal override string EnvPath => Path.Combine(DataLocation.PluginEnvironments, EnvName);
1717

1818
internal override string InstallPath => Path.Combine(EnvPath, "PythonEmbeddable-v3.8.9");
1919

Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class TypeScriptEnvironment : AbstractPluginEnvironment
1313

1414
internal override string EnvName => "Node.js";
1515

16-
internal override string EnvPath => Path.Combine(DataLocation.DataDirectory(), Environments, EnvName);
16+
internal override string EnvPath => Path.Combine(DataLocation.PluginEnvironments, EnvName);
1717

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

Flow.Launcher.Core/Updater.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,29 @@
1717
using Flow.Launcher.Plugin;
1818
using System.Text.Json.Serialization;
1919
using System.Threading;
20+
using System.IO;
21+
using System.Text.RegularExpressions;
2022

2123
namespace Flow.Launcher.Core
2224
{
2325
public class Updater
2426
{
2527
public string GitHubRepository { get; }
2628

29+
private string updatePythonIndicatorFilename = ".updatePythonPath";
30+
31+
private string updateNodeIndicatorFilename = ".updateNodePath";
32+
33+
private string appDataRegex = @"app-\d\.\d\.\d";
34+
2735
public Updater(string gitHubRepository)
2836
{
2937
GitHubRepository = gitHubRepository;
3038
}
3139

3240
private SemaphoreSlim UpdateLock { get; } = new SemaphoreSlim(1);
3341

34-
public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
42+
public async Task UpdateAppAsync(IPublicAPI api, Settings settings, bool silentUpdate = true)
3543
{
3644
await UpdateLock.WaitAsync();
3745
try
@@ -73,6 +81,8 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
7381
MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
7482
DataLocation.PortableDataPath,
7583
targetDestination));
84+
85+
UpdatePluginEnvPaths(settings, newReleaseVersion.ToString());
7686
}
7787
else
7888
{
@@ -145,5 +155,44 @@ public string NewVersionTips(string version)
145155
return tips;
146156
}
147157

158+
private void UpdatePluginEnvPaths(Settings settings, string newVer)
159+
{
160+
var appVer = $"app-{newVer}";
161+
var updatePythonIndicatorFilePath
162+
= Regex.Replace(Path.Combine(DataLocation.PluginEnvironments, updatePythonIndicatorFilename), appDataRegex, appVer);
163+
var updateNodeIndicatorFilePath
164+
= Regex.Replace(Path.Combine(DataLocation.PluginEnvironments, updateNodeIndicatorFilename), appDataRegex, appVer);
165+
166+
if (!string.IsNullOrEmpty(settings.PluginSettings.PythonExecutablePath)
167+
&& settings.PluginSettings.PythonExecutablePath.StartsWith(DataLocation.PluginEnvironments))
168+
using (var _ = File.CreateText(updatePythonIndicatorFilePath)){}
169+
170+
if (!string.IsNullOrEmpty(settings.PluginSettings.NodeExecutablePath)
171+
&& settings.PluginSettings.NodeExecutablePath.StartsWith(DataLocation.PluginEnvironments))
172+
using (var _ = File.CreateText(updateNodeIndicatorFilePath)) { }
173+
}
174+
175+
public void PreStartSetupAfterAppUpdate(Settings settings)
176+
{
177+
var appVer = $"app-{Constant.Version}";
178+
var updatePythonIndicatorFilePath = Path.Combine(DataLocation.PluginEnvironments, updatePythonIndicatorFilename);
179+
var updateNodeIndicatorFilePath = Path.Combine(DataLocation.PluginEnvironments, updateNodeIndicatorFilename);
180+
181+
if (File.Exists(updatePythonIndicatorFilePath))
182+
{
183+
settings.PluginSettings.PythonExecutablePath
184+
= Regex.Replace(settings.PluginSettings.PythonExecutablePath, appDataRegex, appVer);
185+
186+
File.Delete(updatePythonIndicatorFilePath);
187+
}
188+
189+
if (File.Exists(updateNodeIndicatorFilePath))
190+
{
191+
settings.PluginSettings.NodeExecutablePath
192+
= Regex.Replace(settings.PluginSettings.NodeExecutablePath, appDataRegex, appVer);
193+
194+
File.Delete(updateNodeIndicatorFilePath);
195+
}
196+
}
148197
}
149198
}

Flow.Launcher.Infrastructure/UserSettings/DataLocation.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
@@ -31,5 +31,7 @@ public static bool PortableDataLocationInUse()
3131

3232
public static readonly string PluginsDirectory = Path.Combine(DataDirectory(), Constant.Plugins);
3333
public static readonly string PluginSettingsDirectory = Path.Combine(DataDirectory(), "Settings", Constant.Plugins);
34+
35+
public static readonly string PluginEnvironments = Path.Combine(DataDirectory(), "Environments");
3436
}
3537
}

Flow.Launcher/App.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
6161
_settingsVM = new SettingWindowViewModel(_updater, _portable);
6262
_settings = _settingsVM.Settings;
6363

64+
_updater.PreStartSetupAfterAppUpdate(_settings);
65+
6466
_alphabet.Initialize(_settings);
6567
_stringMatcher = new StringMatcher(_alphabet);
6668
StringMatcher.Instance = _stringMatcher;
@@ -135,12 +137,12 @@ private void AutoUpdates()
135137
var timer = new Timer(1000 * 60 * 60 * 5);
136138
timer.Elapsed += async (s, e) =>
137139
{
138-
await _updater.UpdateAppAsync(API);
140+
await _updater.UpdateAppAsync(API, _settings);
139141
};
140142
timer.Start();
141143

142144
// check updates on startup
143-
await _updater.UpdateAppAsync(API);
145+
await _updater.UpdateAppAsync(API, _settings);
144146
}
145147
});
146148
}

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public SettingWindowViewModel(Updater updater, IPortable portable)
6868

6969
public async void UpdateApp()
7070
{
71-
await _updater.UpdateAppAsync(App.API, false);
71+
await _updater.UpdateAppAsync(App.API, Settings, false);
7272
}
7373

7474
public bool AutoUpdates

0 commit comments

Comments
 (0)