From 4f4f1b9cb567b3b084c61683aa0b7d1fcff82fc7 Mon Sep 17 00:00:00 2001 From: rjindael Date: Tue, 1 Aug 2023 23:02:12 -0700 Subject: [PATCH] feat: add back Http tasks (and implement them properly this time) --- Kiseki.Launcher/Helpers/Http.cs | 6 +++--- Kiseki.Launcher/Web.cs | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Kiseki.Launcher/Helpers/Http.cs b/Kiseki.Launcher/Helpers/Http.cs index 4ecd706..5f097e4 100644 --- a/Kiseki.Launcher/Helpers/Http.cs +++ b/Kiseki.Launcher/Helpers/Http.cs @@ -4,12 +4,12 @@ namespace Kiseki.Launcher.Helpers { public static class Http { - public static T? GetJson(string url) + public static async Task GetJson(string url) { try { - string json = Web.HttpClient.GetStringAsync(url).Result; - + string json = await Web.HttpClient.GetStringAsync(url); + return JsonSerializer.Deserialize(json); } catch diff --git a/Kiseki.Launcher/Web.cs b/Kiseki.Launcher/Web.cs index 8c45a94..f686f74 100644 --- a/Kiseki.Launcher/Web.cs +++ b/Kiseki.Launcher/Web.cs @@ -21,8 +21,11 @@ namespace Kiseki.Launcher { CurrentUrl = IsInMaintenance ? $"{MAINTENANCE_DOMAIN}.{BASE_URL}" : BASE_URL; - int response = CheckHealth(); - + Task task = CheckHealth(); + task.Wait(); + + int response = task.Result; + if (response != RESPONSE_SUCCESS) { if (response == RESPONSE_MAINTENANCE) @@ -36,9 +39,9 @@ namespace Kiseki.Launcher public static string Url(string path) => $"https://{CurrentUrl}{path}"; - public static int CheckHealth() + public static async Task CheckHealth() { - var response = Helpers.Http.GetJson(Url("/api/health")); + var response = await Helpers.Http.GetJson(Url("/api/health")); return response is null ? RESPONSE_FAILURE : response.Status; } @@ -54,7 +57,7 @@ namespace Kiseki.Launcher HttpClient.DefaultRequestHeaders.Clear(); var headers = JsonSerializer.Deserialize>(license)!; - + for (int i = 0; i < headers.Count; i++) HttpClient.DefaultRequestHeaders.Add(headers.ElementAt(i).Key, headers.ElementAt(i).Value); }