App: Small changes in auto updater
All checks were successful
Test / Run tests (push) Successful in 2m41s
All checks were successful
Test / Run tests (push) Successful in 2m41s
This commit is contained in:
@ -227,7 +227,7 @@ namespace Elwig {
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task CheckForUpdates(bool showSuccess = false) {
|
||||
public static async Task CheckForUpdates(bool showAlert = false) {
|
||||
if (Config.UpdateUrl == null) return;
|
||||
var latest = await Utils.GetLatestInstallerUrl(Config.UpdateUrl);
|
||||
if (latest != null && new Version(latest.Value.Version) > new Version(Version)) {
|
||||
@ -238,9 +238,14 @@ namespace Elwig {
|
||||
Current.Shutdown();
|
||||
}
|
||||
});
|
||||
} else if (showSuccess) {
|
||||
MessageBox.Show("Elwig ist auf dem aktuellsten Stand!", "Nach Updates suchen",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
} else if (showAlert) {
|
||||
if (latest == null) {
|
||||
MessageBox.Show("Informationen konnten nicht abgerufen werden!", "Nach Updates suchen",
|
||||
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
} else {
|
||||
MessageBox.Show($"Elwig ist auf dem aktuellsten Stand! (Version: {latest.Value.Version})", "Nach Updates suchen",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,8 +425,11 @@ namespace Elwig.Helpers {
|
||||
public static async Task<(string Version, string Url, long Size)?> GetLatestInstallerUrl(string url) {
|
||||
try {
|
||||
using var client = GetHttpClient(accept: "application/json");
|
||||
var resJson = JsonNode.Parse(await client.GetStringAsync(url));
|
||||
var data = resJson!["data"]![0]!;
|
||||
using var res = await client.GetAsync(url);
|
||||
if (!res.IsSuccessStatusCode)
|
||||
return null;
|
||||
var resJson = JsonNode.Parse(await res.Content.ReadAsStringAsync());
|
||||
var data = resJson!["data"]!.AsArray()[^1]!;
|
||||
return ((string)data["version"]!, (string)data["url"]!, (long)data["size"]!);
|
||||
} catch {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user