mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
use Http.Get from Infrastructure
This commit is contained in:
parent
c4b2742198
commit
c8b251d63a
2 changed files with 25 additions and 26 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue