Skip to content

Commit f32e202

Browse files
committed
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.
1 parent bb9682f commit f32e202

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Flow.Launcher.Infrastructure/Http/Http.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,18 @@ public static async Task<string> Get([NotNull] string url, string encoding = "UT
7373

7474
return content;
7575
}
76+
77+
public static async Task<Stream> GetStreamAsync([NotNull] string url, string encoding = "UTF-8")
78+
{
79+
Log.Debug($"|Http.Get|Url <{url}>");
80+
var request = WebRequest.CreateHttp(url);
81+
request.Method = "GET";
82+
request.Timeout = 6000;
83+
request.Proxy = WebProxy();
84+
request.UserAgent = UserAgent;
85+
var response = await request.GetResponseAsync() as HttpWebResponse;
86+
response = response.NonNull();
87+
return response.GetResponseStream().NonNull();
88+
}
7689
}
7790
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Flow.Launcher.Infrastructure.Http;
22
using Flow.Launcher.Infrastructure.Logger;
3-
using Newtonsoft.Json;
43
using System;
54
using System.Collections.Generic;
5+
using System.Text.Json;
66
using System.Threading.Tasks;
77

88
namespace Flow.Launcher.Plugin.PluginsManager.Models
@@ -17,12 +17,12 @@ internal PluginsManifest()
1717

1818
internal async Task DownloadManifest()
1919
{
20-
var json = string.Empty;
2120
try
2221
{
23-
json = await Http.Get("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json");
22+
var jsonStream = await Http.GetStreamAsync("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json")
23+
.ConfigureAwait(false);
2424

25-
UserPlugins = JsonConvert.DeserializeObject<List<UserPlugin>>(json);
25+
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(jsonStream).ConfigureAwait(false);
2626
}
2727
catch (Exception e)
2828
{

0 commit comments

Comments
 (0)