Skip to content

Commit c8b251d

Browse files
committed
use Http.Get from Infrastructure
1 parent c4b2742 commit c8b251d

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

Flow.Launcher.Infrastructure/Http/Http.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,12 @@ public static async Task<string> Get([NotNull] string url, string encoding = "UT
6666
response = response.NonNull();
6767
var stream = response.GetResponseStream().NonNull();
6868

69-
using (var reader = new StreamReader(stream, Encoding.GetEncoding(encoding)))
70-
{
71-
var content = await reader.ReadToEndAsync();
72-
if (response.StatusCode == HttpStatusCode.OK)
73-
{
74-
return content;
75-
}
76-
else
77-
{
78-
throw new HttpRequestException($"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
79-
}
80-
}
69+
using var reader = new StreamReader(stream, Encoding.GetEncoding(encoding));
70+
var content = await reader.ReadToEndAsync();
71+
if (response.StatusCode != HttpStatusCode.OK)
72+
throw new HttpRequestException($"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
73+
74+
return content;
8175
}
8276
}
8377
}

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,38 @@
33
using Newtonsoft.Json;
44
using System;
55
using System.Collections.Generic;
6-
using System.Net;
7-
using System.Text;
6+
using System.Threading.Tasks;
87

98
namespace Flow.Launcher.Plugin.PluginsManager.Models
109
{
1110
internal class PluginsManifest
1211
{
1312
internal List<UserPlugin> UserPlugins { get; private set; }
1413
internal PluginsManifest()
14+
{
15+
DownloadManifest();
16+
}
17+
18+
private void DownloadManifest()
1519
{
1620
var json = string.Empty;
21+
try
22+
{
23+
var t = Task.Run(
24+
async () =>
25+
json = await Http.Get("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json"));
26+
27+
t.Wait();
1728

18-
using (var wc = new WebClient { Proxy = Http.WebProxy() })
29+
UserPlugins = JsonConvert.DeserializeObject<List<UserPlugin>>(json);
30+
}
31+
catch (Exception e)
1932
{
20-
try
21-
{
22-
json = wc.DownloadString("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json");
23-
}
24-
catch (Exception e)
25-
{
26-
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
33+
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
2734

28-
UserPlugins = new List<UserPlugin>();
29-
}
35+
UserPlugins = new List<UserPlugin>();
3036
}
3137

32-
UserPlugins = !string.IsNullOrEmpty(json) ? JsonConvert.DeserializeObject<List<UserPlugin>>(json) : new List<UserPlugin>();
3338
}
3439
}
3540
}

0 commit comments

Comments
 (0)