mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
pass CancellationToken to PluginsManifest.UpdateManifestAsync
This commit is contained in:
parent
33fb0ddee6
commit
35e043859c
2 changed files with 10 additions and 14 deletions
|
|
@ -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<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
|
||||
|
||||
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<List<UserPlugin>>(json).ConfigureAwait(false);
|
||||
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(json, cancellationToken: token).ConfigureAwait(false);
|
||||
|
||||
latestEtag = response.Headers.ETag.Tag;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<List<Result>> 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<List<Result>> RequestInstallOrUpdate(string searchName, CancellationToken token)
|
||||
{
|
||||
await UpdateManifestAsync();
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
await UpdateManifestAsync(token);
|
||||
|
||||
var searchNameWithoutKeyword = searchName.Replace(Settings.HotKeyInstall, string.Empty, StringComparison.OrdinalIgnoreCase).Trim();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue