Use System.Text.JsonSerializer.DeserializeAsync instead of Newtonsoft.Json since our plugins.json can be large, so no need to create an extra string to store it.

This commit is contained in:
弘韬 张 2020-12-29 12:20:13 +08:00
parent bb9682f791
commit f32e202746
2 changed files with 17 additions and 4 deletions

View file

@ -73,5 +73,18 @@ namespace Flow.Launcher.Infrastructure.Http
return content;
}
public static async Task<Stream> GetStreamAsync([NotNull] string url, string encoding = "UTF-8")
{
Log.Debug($"|Http.Get|Url <{url}>");
var request = WebRequest.CreateHttp(url);
request.Method = "GET";
request.Timeout = 6000;
request.Proxy = WebProxy();
request.UserAgent = UserAgent;
var response = await request.GetResponseAsync() as HttpWebResponse;
response = response.NonNull();
return response.GetResponseStream().NonNull();
}
}
}

View file

@ -1,8 +1,8 @@
using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Logger;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
namespace Flow.Launcher.Plugin.PluginsManager.Models
@ -17,12 +17,12 @@ namespace Flow.Launcher.Plugin.PluginsManager.Models
internal async Task DownloadManifest()
{
var json = string.Empty;
try
{
json = await Http.Get("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json");
var jsonStream = await Http.GetStreamAsync("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json")
.ConfigureAwait(false);
UserPlugins = JsonConvert.DeserializeObject<List<UserPlugin>>(json);
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(jsonStream).ConfigureAwait(false);
}
catch (Exception e)
{