diff --git a/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs b/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs index e3df7d31f..f72543a90 100644 --- a/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs +++ b/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs @@ -14,8 +14,6 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments { internal abstract string Language { get; } - internal const string Environments = "Environments"; - internal abstract string EnvName { get; } internal abstract string EnvPath { get; } @@ -37,7 +35,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments PluginMetadataList = pluginMetadataList; PluginSettings = pluginSettings; } - //TODO: CHECK IF NEED TO RESET PATH AFTER FLOW UPDATE + internal IEnumerable Setup() { if (!PluginMetadataList.Any(o => o.Language.Equals(Language, StringComparison.OrdinalIgnoreCase))) diff --git a/Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs b/Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs index 3d670be95..23517e37f 100644 --- a/Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs +++ b/Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs @@ -13,7 +13,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments internal override string EnvName => "Python"; - internal override string EnvPath => Path.Combine(DataLocation.DataDirectory(), Environments, EnvName); + internal override string EnvPath => Path.Combine(DataLocation.PluginEnvironments, EnvName); internal override string InstallPath => Path.Combine(EnvPath, "PythonEmbeddable-v3.8.9"); diff --git a/Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs b/Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs index 4534c9106..d70b5dc31 100644 --- a/Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs +++ b/Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs @@ -13,7 +13,7 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments internal override string EnvName => "Node.js"; - internal override string EnvPath => Path.Combine(DataLocation.DataDirectory(), Environments, EnvName); + internal override string EnvPath => Path.Combine(DataLocation.PluginEnvironments, 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"); diff --git a/Flow.Launcher.Core/Updater.cs b/Flow.Launcher.Core/Updater.cs index 44c47cf28..e9f25b3ee 100644 --- a/Flow.Launcher.Core/Updater.cs +++ b/Flow.Launcher.Core/Updater.cs @@ -17,6 +17,8 @@ using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using System.Text.Json.Serialization; using System.Threading; +using System.IO; +using System.Text.RegularExpressions; namespace Flow.Launcher.Core { @@ -24,6 +26,12 @@ namespace Flow.Launcher.Core { public string GitHubRepository { get; } + private string updatePythonIndicatorFilename = ".updatePythonPath"; + + private string updateNodeIndicatorFilename = ".updateNodePath"; + + private string appDataRegex = @"app-\d\.\d\.\d"; + public Updater(string gitHubRepository) { GitHubRepository = gitHubRepository; @@ -31,7 +39,7 @@ namespace Flow.Launcher.Core private SemaphoreSlim UpdateLock { get; } = new SemaphoreSlim(1); - public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true) + public async Task UpdateAppAsync(IPublicAPI api, Settings settings, bool silentUpdate = true) { await UpdateLock.WaitAsync(); try @@ -73,6 +81,8 @@ namespace Flow.Launcher.Core MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"), DataLocation.PortableDataPath, targetDestination)); + + UpdatePluginEnvPaths(settings, newReleaseVersion.ToString()); } else { @@ -145,5 +155,44 @@ namespace Flow.Launcher.Core return tips; } + private void UpdatePluginEnvPaths(Settings settings, string newVer) + { + var appVer = $"app-{newVer}"; + var updatePythonIndicatorFilePath + = Regex.Replace(Path.Combine(DataLocation.PluginEnvironments, updatePythonIndicatorFilename), appDataRegex, appVer); + var updateNodeIndicatorFilePath + = Regex.Replace(Path.Combine(DataLocation.PluginEnvironments, updateNodeIndicatorFilename), appDataRegex, appVer); + + if (!string.IsNullOrEmpty(settings.PluginSettings.PythonExecutablePath) + && settings.PluginSettings.PythonExecutablePath.StartsWith(DataLocation.PluginEnvironments)) + using (var _ = File.CreateText(updatePythonIndicatorFilePath)){} + + if (!string.IsNullOrEmpty(settings.PluginSettings.NodeExecutablePath) + && settings.PluginSettings.NodeExecutablePath.StartsWith(DataLocation.PluginEnvironments)) + using (var _ = File.CreateText(updateNodeIndicatorFilePath)) { } + } + + public void PreStartSetupAfterAppUpdate(Settings settings) + { + var appVer = $"app-{Constant.Version}"; + var updatePythonIndicatorFilePath = Path.Combine(DataLocation.PluginEnvironments, updatePythonIndicatorFilename); + var updateNodeIndicatorFilePath = Path.Combine(DataLocation.PluginEnvironments, updateNodeIndicatorFilename); + + if (File.Exists(updatePythonIndicatorFilePath)) + { + settings.PluginSettings.PythonExecutablePath + = Regex.Replace(settings.PluginSettings.PythonExecutablePath, appDataRegex, appVer); + + File.Delete(updatePythonIndicatorFilePath); + } + + if (File.Exists(updateNodeIndicatorFilePath)) + { + settings.PluginSettings.NodeExecutablePath + = Regex.Replace(settings.PluginSettings.NodeExecutablePath, appDataRegex, appVer); + + File.Delete(updateNodeIndicatorFilePath); + } + } } } diff --git a/Flow.Launcher.Infrastructure/UserSettings/DataLocation.cs b/Flow.Launcher.Infrastructure/UserSettings/DataLocation.cs index e93c341dc..0eeafabd4 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/DataLocation.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/DataLocation.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -31,5 +31,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings public static readonly string PluginsDirectory = Path.Combine(DataDirectory(), Constant.Plugins); public static readonly string PluginSettingsDirectory = Path.Combine(DataDirectory(), "Settings", Constant.Plugins); + + public static readonly string PluginEnvironments = Path.Combine(DataDirectory(), "Environments"); } } diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index cb8e79d63..3fa69262d 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -61,6 +61,8 @@ namespace Flow.Launcher _settingsVM = new SettingWindowViewModel(_updater, _portable); _settings = _settingsVM.Settings; + _updater.PreStartSetupAfterAppUpdate(_settings); + _alphabet.Initialize(_settings); _stringMatcher = new StringMatcher(_alphabet); StringMatcher.Instance = _stringMatcher; @@ -135,12 +137,12 @@ namespace Flow.Launcher var timer = new Timer(1000 * 60 * 60 * 5); timer.Elapsed += async (s, e) => { - await _updater.UpdateAppAsync(API); + await _updater.UpdateAppAsync(API, _settings); }; timer.Start(); // check updates on startup - await _updater.UpdateAppAsync(API); + await _updater.UpdateAppAsync(API, _settings); } }); } diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 5514951b1..69c5fd40f 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -68,7 +68,7 @@ namespace Flow.Launcher.ViewModel public async void UpdateApp() { - await _updater.UpdateAppAsync(App.API, false); + await _updater.UpdateAppAsync(App.API, Settings, false); } public bool AutoUpdates