diff --git a/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs b/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs index dc1c0cc21..d3b9c5a8e 100644 --- a/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs +++ b/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Infrastructure.Logger; using System; using System.Collections.Generic; using System.Net; @@ -21,24 +21,24 @@ namespace Flow.Launcher.Core.ExternalPlugins public static List UserPlugins { get; private set; } = new List(); - public static async Task UpdateManifestAsync() + public static async Task UpdateManifestAsync(CancellationToken token = default) { try { - await manifestUpdateLock.WaitAsync().ConfigureAwait(false); + await manifestUpdateLock.WaitAsync(token).ConfigureAwait(false); var request = new HttpRequestMessage(HttpMethod.Get, manifestFileUrl); request.Headers.Add("If-None-Match", latestEtag); - var response = await httpClient.SendAsync(request).ConfigureAwait(false); + var response = await httpClient.SendAsync(request, token).ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.OK) { Log.Info($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Fetched plugins from manifest repo"); - var json = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); + var json = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false); - UserPlugins = await JsonSerializer.DeserializeAsync>(json).ConfigureAwait(false); + UserPlugins = await JsonSerializer.DeserializeAsync>(json, cancellationToken: token).ConfigureAwait(false); latestEtag = response.Headers.ETag.Tag; } diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index aed5f5e2f..17f220b70 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -51,7 +51,7 @@ namespace Flow.Launcher.Plugin.PluginsManager private Task _downloadManifestTask = Task.CompletedTask; - internal Task UpdateManifestAsync(bool silent = false) + internal Task UpdateManifestAsync(CancellationToken token = default, bool silent = false) { if (_downloadManifestTask.Status == TaskStatus.Running) { @@ -59,7 +59,7 @@ namespace Flow.Launcher.Plugin.PluginsManager } else { - _downloadManifestTask = PluginsManifest.UpdateManifestAsync(); + _downloadManifestTask = PluginsManifest.UpdateManifestAsync(token); if (!silent) _downloadManifestTask.ContinueWith(_ => Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_failed_title"), @@ -181,9 +181,7 @@ namespace Flow.Launcher.Plugin.PluginsManager internal async ValueTask> RequestUpdate(string search, CancellationToken token) { - await UpdateManifestAsync(); - - token.ThrowIfCancellationRequested(); + await UpdateManifestAsync(token); var autocompletedResults = AutoCompleteReturnAllResults(search, Settings.HotkeyUpdate, @@ -368,9 +366,7 @@ namespace Flow.Launcher.Plugin.PluginsManager internal async ValueTask> RequestInstallOrUpdate(string searchName, CancellationToken token) { - await UpdateManifestAsync(); - - token.ThrowIfCancellationRequested(); + await UpdateManifestAsync(token); var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty, StringComparison.OrdinalIgnoreCase).Trim();