update setting's environment file paths after app update

This commit is contained in:
Jeremy Wu 2022-11-28 08:44:42 +11:00
parent 2dba51861f
commit 9eb5489863
7 changed files with 61 additions and 10 deletions

View file

@ -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<PluginPair> Setup()
{
if (!PluginMetadataList.Any(o => o.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)))

View file

@ -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");

View file

@ -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");

View file

@ -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);
}
}
}
}

View file

@ -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");
}
}

View file

@ -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);
}
});
}

View file

@ -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