Skip to content

Commit 35e0438

Browse files
committed
pass CancellationToken to PluginsManifest.UpdateManifestAsync
1 parent 33fb0dd commit 35e0438

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Flow.Launcher.Infrastructure.Logger;
1+
using Flow.Launcher.Infrastructure.Logger;
22
using System;
33
using System.Collections.Generic;
44
using System.Net;
@@ -21,24 +21,24 @@ public static class PluginsManifest
2121

2222
public static List<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
2323

24-
public static async Task UpdateManifestAsync()
24+
public static async Task UpdateManifestAsync(CancellationToken token = default)
2525
{
2626
try
2727
{
28-
await manifestUpdateLock.WaitAsync().ConfigureAwait(false);
28+
await manifestUpdateLock.WaitAsync(token).ConfigureAwait(false);
2929

3030
var request = new HttpRequestMessage(HttpMethod.Get, manifestFileUrl);
3131
request.Headers.Add("If-None-Match", latestEtag);
3232

33-
var response = await httpClient.SendAsync(request).ConfigureAwait(false);
33+
var response = await httpClient.SendAsync(request, token).ConfigureAwait(false);
3434

3535
if (response.StatusCode == HttpStatusCode.OK)
3636
{
3737
Log.Info($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Fetched plugins from manifest repo");
3838

39-
var json = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
39+
var json = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false);
4040

41-
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(json).ConfigureAwait(false);
41+
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(json, cancellationToken: token).ConfigureAwait(false);
4242

4343
latestEtag = response.Headers.ETag.Tag;
4444
}

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ internal PluginsManager(PluginInitContext context, Settings settings)
5151

5252
private Task _downloadManifestTask = Task.CompletedTask;
5353

54-
internal Task UpdateManifestAsync(bool silent = false)
54+
internal Task UpdateManifestAsync(CancellationToken token = default, bool silent = false)
5555
{
5656
if (_downloadManifestTask.Status == TaskStatus.Running)
5757
{
5858
return _downloadManifestTask;
5959
}
6060
else
6161
{
62-
_downloadManifestTask = PluginsManifest.UpdateManifestAsync();
62+
_downloadManifestTask = PluginsManifest.UpdateManifestAsync(token);
6363
if (!silent)
6464
_downloadManifestTask.ContinueWith(_ =>
6565
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_failed_title"),
@@ -181,9 +181,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
181181

182182
internal async ValueTask<List<Result>> RequestUpdate(string search, CancellationToken token)
183183
{
184-
await UpdateManifestAsync();
185-
186-
token.ThrowIfCancellationRequested();
184+
await UpdateManifestAsync(token);
187185

188186
var autocompletedResults = AutoCompleteReturnAllResults(search,
189187
Settings.HotkeyUpdate,
@@ -368,9 +366,7 @@ private bool InstallSourceKnown(string url)
368366

369367
internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName, CancellationToken token)
370368
{
371-
await UpdateManifestAsync();
372-
373-
token.ThrowIfCancellationRequested();
369+
await UpdateManifestAsync(token);
374370

375371
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty, StringComparison.OrdinalIgnoreCase).Trim();
376372

0 commit comments

Comments
 (0)