Skip to content

Commit 5f2dd1a

Browse files
committed
Change plugin update check function
1 parent d400cda commit 5f2dd1a

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

Flow.Launcher.Core/Plugin/PluginInstaller.cs

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,12 @@ await DownloadFileAsync(
281281
/// <summary>
282282
/// Updates the plugin to the latest version available from its source.
283283
/// </summary>
284+
/// <param name="updateAllPlugins">Action to execute when the user chooses to update all plugins.</param>
284285
/// <param name="silentUpdate">If true, do not show any messages when there is no update available.</param>
285286
/// <param name="usePrimaryUrlOnly">If true, only use the primary URL for updates.</param>
286287
/// <param name="token">Cancellation token to cancel the update operation.</param>
287288
/// <returns></returns>
288-
public static async Task CheckForPluginUpdatesAsync(bool silentUpdate = true, bool usePrimaryUrlOnly = false, CancellationToken token = default)
289+
public static async Task CheckForPluginUpdatesAsync(Action<List<PluginUpdateInfo>> updateAllPlugins, bool silentUpdate = true, bool usePrimaryUrlOnly = false, CancellationToken token = default)
289290
{
290291
// Update the plugin manifest
291292
await API.UpdatePluginManifestAsync(usePrimaryUrlOnly, token);
@@ -334,14 +335,20 @@ where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version
334335
API.GetTranslation("updateAllPluginsButtonContent"),
335336
() =>
336337
{
337-
UpdateAllPlugins(resultsForUpdate);
338+
updateAllPlugins(resultsForUpdate);
338339
},
339340
string.Join(", ", resultsForUpdate.Select(x => x.PluginExistingMetadata.Name)));
340341
}
341342

342-
private static void UpdateAllPlugins(IEnumerable<PluginUpdateInfo> resultsForUpdate)
343+
/// <summary>
344+
/// Updates all plugins that have available updates.
345+
/// </summary>
346+
/// <param name="resultsForUpdate"></param>
347+
/// <param name="restart"></param>
348+
public static async Task UpdateAllPluginsAsync(IEnumerable<PluginUpdateInfo> resultsForUpdate, bool restart)
343349
{
344-
_ = Task.WhenAll(resultsForUpdate.Select(async plugin =>
350+
var anyPluginSuccess = false;
351+
await Task.WhenAll(resultsForUpdate.Select(async plugin =>
345352
{
346353
var downloadToFilePath = Path.Combine(Path.GetTempPath(), $"{plugin.Name}-{plugin.NewVersion}.zip");
347354

@@ -363,13 +370,28 @@ await DownloadFileAsync(
363370
{
364371
return;
365372
}
373+
374+
anyPluginSuccess = true;
366375
}
367376
catch (Exception e)
368377
{
369378
API.LogException(ClassName, "Failed to update plugin", e);
370379
API.ShowMsgError(API.GetTranslation("ErrorUpdatingPlugin"));
371380
}
372381
}));
382+
383+
if (!anyPluginSuccess) return;
384+
385+
if (restart)
386+
{
387+
API.RestartApp();
388+
}
389+
else
390+
{
391+
API.ShowMsg(
392+
API.GetTranslation("updatebtn"),
393+
API.GetTranslation("PluginsUpdateSuccessNoRestart"));
394+
}
373395
}
374396

375397
/// <summary>
@@ -445,16 +467,16 @@ private static bool InstallSourceKnown(string url)
445467
x.Metadata.Website.StartsWith(constructedUrlPart)
446468
);
447469
}
470+
}
448471

449-
private record PluginUpdateInfo
450-
{
451-
public string ID { get; init; }
452-
public string Name { get; init; }
453-
public string Author { get; init; }
454-
public string CurrentVersion { get; init; }
455-
public string NewVersion { get; init; }
456-
public string IcoPath { get; init; }
457-
public PluginMetadata PluginExistingMetadata { get; init; }
458-
public UserPlugin PluginNewUserPlugin { get; init; }
459-
}
472+
public record PluginUpdateInfo
473+
{
474+
public string ID { get; init; }
475+
public string Name { get; init; }
476+
public string Author { get; init; }
477+
public string CurrentVersion { get; init; }
478+
public string NewVersion { get; init; }
479+
public string IcoPath { get; init; }
480+
public PluginMetadata PluginExistingMetadata { get; init; }
481+
public UserPlugin PluginNewUserPlugin { get; init; }
460482
}

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
<system:String x:Key="updateAllPluginsTitle">Plugin updates available</system:String>
240240
<system:String x:Key="updateAllPluginsButtonContent">Update all plugins</system:String>
241241
<system:String x:Key="checkPluginUpdatesTooltip">Check plugin updates</system:String>
242+
<system:String x:Key="PluginsUpdateSuccessNoRestart">Plugins are successfully updated. Please restart Flow.</system:String>
242243

243244
<!-- Setting Theme -->
244245
<system:String x:Key="theme">Theme</system:String>

0 commit comments

Comments
 (0)