From f32e202746397e6542f5a831b8b675ce5e1878c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Tue, 29 Dec 2020 12:20:13 +0800 Subject: [PATCH] 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. --- Flow.Launcher.Infrastructure/Http/Http.cs | 13 +++++++++++++ .../Models/PluginsManifest.cs | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Http/Http.cs b/Flow.Launcher.Infrastructure/Http/Http.cs index 2d798ec11..62cacc18f 100644 --- a/Flow.Launcher.Infrastructure/Http/Http.cs +++ b/Flow.Launcher.Infrastructure/Http/Http.cs @@ -73,5 +73,18 @@ namespace Flow.Launcher.Infrastructure.Http return content; } + + public static async Task 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(); + } } } \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Models/PluginsManifest.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/Models/PluginsManifest.cs index 1c31432b2..2ab8806bc 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/Models/PluginsManifest.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/Models/PluginsManifest.cs @@ -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>(json); + UserPlugins = await JsonSerializer.DeserializeAsync>(jsonStream).ConfigureAwait(false); } catch (Exception e) {