Skip to content

Commit e1e8951

Browse files
committed
remove duplicated updater pre-startup methods
1 parent 87e49cd commit e1e8951

File tree

4 files changed

+11
-55
lines changed

4 files changed

+11
-55
lines changed

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

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -157,56 +157,13 @@ private string GetFileFromDialog(string title, string filter = "")
157157
}
158158
}
159159

160-
public static void IndicatePluginEnvPathsUpdate(Settings settings, string newVer)
161-
{
162-
var appVer = $"app-{newVer}";
163-
var updatePythonIndicatorFilePath
164-
= Regex.Replace(Path.Combine(DataLocation.PluginEnvironments, updatePythonIndicatorFilename), appDataRegex, appVer);
165-
var updateNodeIndicatorFilePath
166-
= Regex.Replace(Path.Combine(DataLocation.PluginEnvironments, updateNodeIndicatorFilename), appDataRegex, appVer);
167-
168-
if (!string.IsNullOrEmpty(settings.PluginSettings.PythonExecutablePath)
169-
&& settings.PluginSettings.PythonExecutablePath.StartsWith(DataLocation.PluginEnvironments))
170-
using (var _ = File.CreateText(updatePythonIndicatorFilePath)) { }
171-
172-
if (!string.IsNullOrEmpty(settings.PluginSettings.NodeExecutablePath)
173-
&& settings.PluginSettings.NodeExecutablePath.StartsWith(DataLocation.PluginEnvironments))
174-
using (var _ = File.CreateText(updateNodeIndicatorFilePath)) { }
175-
}
176-
160+
/// <summary>
161+
/// After app updated while in portable mode or switched between portable/roaming mode,
162+
/// need to update each plugin's executable path so user will not be prompted again to reinstall the environments.
163+
/// </summary>
164+
/// <param name="settings"></param>
177165
public static void PreStartPluginFilePathCorrection(Settings settings)
178166
{
179-
PreStartCorrectionAfterUpdate(settings);
180-
PreStartCorrectionAfterModeChange(settings);
181-
}
182-
183-
private static void PreStartCorrectionAfterUpdate(Settings settings)
184-
{
185-
// After updating flow, update plugin env paths.
186-
var appVer = $"app-{Constant.Version}";
187-
var updatePythonIndicatorFilePath = Path.Combine(DataLocation.PluginEnvironments, updatePythonIndicatorFilename);
188-
var updateNodeIndicatorFilePath = Path.Combine(DataLocation.PluginEnvironments, updateNodeIndicatorFilename);
189-
190-
if (File.Exists(updatePythonIndicatorFilePath))
191-
{
192-
settings.PluginSettings.PythonExecutablePath
193-
= Regex.Replace(settings.PluginSettings.PythonExecutablePath, appDataRegex, appVer);
194-
195-
File.Delete(updatePythonIndicatorFilePath);
196-
}
197-
198-
if (File.Exists(updateNodeIndicatorFilePath))
199-
{
200-
settings.PluginSettings.NodeExecutablePath
201-
= Regex.Replace(settings.PluginSettings.NodeExecutablePath, appDataRegex, appVer);
202-
203-
File.Delete(updateNodeIndicatorFilePath);
204-
}
205-
}
206-
207-
private static void PreStartCorrectionAfterModeChange(Settings settings)
208-
{
209-
// After enabling/disabling portable mode, update plugin env paths.
210167
if (DataLocation.PortableDataLocationInUse())
211168
{
212169
// When user is using portable but has moved flow to a different location
@@ -251,6 +208,8 @@ private static void PreStartCorrectionAfterModeChange(Settings settings)
251208

252209
private static bool IsUsingPortablePath(string filePath, string pluginEnvironmentName)
253210
{
211+
// DataLocation.PortableDataPath returns the current portable path, this determines if an out
212+
// of date path is also a portable path.
254213
var portableAppEnvLocation = $"UserData\\{DataLocation.PluginEnvironments}\\{pluginEnvironmentName}";
255214

256215
return filePath.Contains(portableAppEnvLocation);

Flow.Launcher.Core/Updater.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using Flow.Launcher.Plugin;
1818
using System.Text.Json.Serialization;
1919
using System.Threading;
20-
using Flow.Launcher.Core.ExternalPlugins.Environments;
2120

2221
namespace Flow.Launcher.Core
2322
{
@@ -32,7 +31,7 @@ public Updater(string gitHubRepository)
3231

3332
private SemaphoreSlim UpdateLock { get; } = new SemaphoreSlim(1);
3433

35-
public async Task UpdateAppAsync(IPublicAPI api, Settings settings, bool silentUpdate = true)
34+
public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
3635
{
3736
await UpdateLock.WaitAsync();
3837
try
@@ -74,8 +73,6 @@ public async Task UpdateAppAsync(IPublicAPI api, Settings settings, bool silentU
7473
MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
7574
DataLocation.PortableDataPath,
7675
targetDestination));
77-
78-
AbstractPluginEnvironment.IndicatePluginEnvPathsUpdate(settings, newReleaseVersion.ToString());
7976
}
8077
else
8178
{

Flow.Launcher/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ private void AutoUpdates()
138138
var timer = new Timer(1000 * 60 * 60 * 5);
139139
timer.Elapsed += async (s, e) =>
140140
{
141-
await _updater.UpdateAppAsync(API, _settings);
141+
await _updater.UpdateAppAsync(API);
142142
};
143143
timer.Start();
144144

145145
// check updates on startup
146-
await _updater.UpdateAppAsync(API, _settings);
146+
await _updater.UpdateAppAsync(API);
147147
}
148148
});
149149
}

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, Settings, false);
71+
await _updater.UpdateAppAsync(App.API, false);
7272
}
7373

7474
public bool AutoUpdates

0 commit comments

Comments
 (0)