use Http.Get from Infrastructure

This commit is contained in:
Jeremy Wu 2020-12-14 08:41:18 +11:00
parent c4b2742198
commit c8b251d63a
2 changed files with 25 additions and 26 deletions

View file

@ -66,18 +66,12 @@ namespace Flow.Launcher.Infrastructure.Http
response = response.NonNull();
var stream = response.GetResponseStream().NonNull();
using (var reader = new StreamReader(stream, Encoding.GetEncoding(encoding)))
{
var content = await reader.ReadToEndAsync();
if (response.StatusCode == HttpStatusCode.OK)
{
return content;
}
else
{
throw new HttpRequestException($"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
}
}
using var reader = new StreamReader(stream, Encoding.GetEncoding(encoding));
var content = await reader.ReadToEndAsync();
if (response.StatusCode != HttpStatusCode.OK)
throw new HttpRequestException($"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
return content;
}
}
}

View file

@ -3,8 +3,7 @@ using Flow.Launcher.Infrastructure.Logger;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Flow.Launcher.Plugin.PluginsManager.Models
{
@ -12,24 +11,30 @@ namespace Flow.Launcher.Plugin.PluginsManager.Models
{
internal List<UserPlugin> UserPlugins { get; private set; }
internal PluginsManifest()
{
DownloadManifest();
}
private void DownloadManifest()
{
var json = string.Empty;
using (var wc = new WebClient { Proxy = Http.WebProxy() })
try
{
try
{
json = wc.DownloadString("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json");
}
catch (Exception e)
{
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
var t = Task.Run(
async () =>
json = await Http.Get("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json"));
UserPlugins = new List<UserPlugin>();
}
t.Wait();
UserPlugins = JsonConvert.DeserializeObject<List<UserPlugin>>(json);
}
catch (Exception e)
{
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
UserPlugins = new List<UserPlugin>();
}
UserPlugins = !string.IsNullOrEmpty(json) ? JsonConvert.DeserializeObject<List<UserPlugin>>(json) : new List<UserPlugin>();
}
}
}