Change usage of Http in Updater.cs and adding ConfigureAwait(false) for await in checking update

This commit is contained in:
弘韬 张 2020-12-29 17:54:39 +08:00
parent 0c97db04d4
commit efa4908f37

View file

@ -29,7 +29,7 @@ namespace Flow.Launcher.Core
GitHubRepository = gitHubRepository;
}
public async Task UpdateApp(IPublicAPI api , bool silentUpdate = true)
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
{
UpdateManager updateManager;
UpdateInfo newUpdateInfo;
@ -39,7 +39,7 @@ namespace Flow.Launcher.Core
try
{
updateManager = await GitHubUpdateManager(GitHubRepository);
updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false);
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
@ -50,7 +50,7 @@ namespace Flow.Launcher.Core
try
{
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
newUpdateInfo = await updateManager.CheckForUpdate().NonNull();
newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false);
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
@ -85,8 +85,8 @@ namespace Flow.Launcher.Core
updateManager.Dispose();
return;
}
await updateManager.ApplyReleases(newUpdateInfo);
await updateManager.ApplyReleases(newUpdateInfo).ConfigureAwait(false);
if (DataLocation.PortableDataLocationInUse())
{
@ -98,11 +98,11 @@ namespace Flow.Launcher.Core
}
else
{
await updateManager.CreateUninstallerRegistryEntry();
await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false);
}
var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
// always dispose UpdateManager
@ -133,9 +133,9 @@ namespace Flow.Launcher.Core
var uri = new Uri(repository);
var api = $"https://api.github.com/repos{uri.AbsolutePath}/releases";
var json = await Http.GetAsync(api);
var jsonStream = await Http.GetStreamAsync(api).ConfigureAwait(false);
var releases = JsonConvert.DeserializeObject<List<GithubRelease>>(json);
var releases = await System.Text.Json.JsonSerializer.DeserializeAsync<List<GithubRelease>>(jsonStream).ConfigureAwait(false);
var latest = releases.Where(r => !r.Prerelease).OrderByDescending(r => r.PublishedAt).First();
var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/");