remove duplicated updater pre-startup methods

This commit is contained in:
Jeremy 2022-12-01 20:58:31 +11:00
parent 87e49cdb7c
commit e1e89514d4
4 changed files with 11 additions and 55 deletions

View file

@ -157,56 +157,13 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
}
}
public static void IndicatePluginEnvPathsUpdate(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)) { }
}
/// <summary>
/// After app updated while in portable mode or switched between portable/roaming mode,
/// need to update each plugin's executable path so user will not be prompted again to reinstall the environments.
/// </summary>
/// <param name="settings"></param>
public static void PreStartPluginFilePathCorrection(Settings settings)
{
PreStartCorrectionAfterUpdate(settings);
PreStartCorrectionAfterModeChange(settings);
}
private static void PreStartCorrectionAfterUpdate(Settings settings)
{
// After updating flow, update plugin env paths.
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);
}
}
private static void PreStartCorrectionAfterModeChange(Settings settings)
{
// After enabling/disabling portable mode, update plugin env paths.
if (DataLocation.PortableDataLocationInUse())
{
// When user is using portable but has moved flow to a different location
@ -251,6 +208,8 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
private static bool IsUsingPortablePath(string filePath, string pluginEnvironmentName)
{
// DataLocation.PortableDataPath returns the current portable path, this determines if an out
// of date path is also a portable path.
var portableAppEnvLocation = $"UserData\\{DataLocation.PluginEnvironments}\\{pluginEnvironmentName}";
return filePath.Contains(portableAppEnvLocation);

View file

@ -17,7 +17,6 @@ using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using System.Text.Json.Serialization;
using System.Threading;
using Flow.Launcher.Core.ExternalPlugins.Environments;
namespace Flow.Launcher.Core
{
@ -32,7 +31,7 @@ namespace Flow.Launcher.Core
private SemaphoreSlim UpdateLock { get; } = new SemaphoreSlim(1);
public async Task UpdateAppAsync(IPublicAPI api, Settings settings, bool silentUpdate = true)
public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
{
await UpdateLock.WaitAsync();
try
@ -74,8 +73,6 @@ namespace Flow.Launcher.Core
MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
DataLocation.PortableDataPath,
targetDestination));
AbstractPluginEnvironment.IndicatePluginEnvPathsUpdate(settings, newReleaseVersion.ToString());
}
else
{

View file

@ -138,12 +138,12 @@ namespace Flow.Launcher
var timer = new Timer(1000 * 60 * 60 * 5);
timer.Elapsed += async (s, e) =>
{
await _updater.UpdateAppAsync(API, _settings);
await _updater.UpdateAppAsync(API);
};
timer.Start();
// check updates on startup
await _updater.UpdateAppAsync(API, _settings);
await _updater.UpdateAppAsync(API);
}
});
}

View file

@ -68,7 +68,7 @@ namespace Flow.Launcher.ViewModel
public async void UpdateApp()
{
await _updater.UpdateAppAsync(App.API, Settings, false);
await _updater.UpdateAppAsync(App.API, false);
}
public bool AutoUpdates