Remove inner try on Updater.CheckGitLabVersionAsync & apply formatting to file

This commit is contained in:
GreemDev 2025-06-03 17:56:11 -05:00
parent 64ecd514f2
commit 91248bdd32

View File

@ -18,12 +18,14 @@ namespace Ryujinx.Ava.Systems
internal static partial class Updater
{
private static GitLabReleaseChannels.ChannelType _currentGitLabReleaseChannel;
private static async Task<Optional<(Version Current, Version Incoming)>> CheckGitLabVersionAsync(bool showVersionUpToDate = false)
private static async Task<Optional<(Version Current, Version Incoming)>> CheckGitLabVersionAsync(
bool showVersionUpToDate = false)
{
if (!Version.TryParse(Program.Version, out Version currentVersion))
{
Logger.Error?.Print(LogClass.Application, $"Failed to convert the current {RyujinxApp.FullAppName} version!");
Logger.Error?.Print(LogClass.Application,
$"Failed to convert the current {RyujinxApp.FullAppName} version!");
await ContentDialogHelper.CreateWarningDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedMessage],
@ -37,70 +39,61 @@ namespace Ryujinx.Ava.Systems
Logger.Info?.Print(LogClass.Application, "Checking for updates from https://git.ryujinx.app.");
// Get latest version number from GitLab API
try
using HttpClient jsonClient = ConstructHttpClient();
jsonClient.Timeout =
TimeSpan.FromSeconds(
10); // GitLab instance is located in Ukraine. Connection times will vary across the world.
if (_currentGitLabReleaseChannel == null)
{
using HttpClient jsonClient = ConstructHttpClient();
GitLabReleaseChannels releaseChannels = await GitLabReleaseChannels.GetAsync(jsonClient);
jsonClient.Timeout = TimeSpan.FromSeconds(10); // GitLab instance is located in Ukraine. Connection times will vary across the world.
_currentGitLabReleaseChannel = ReleaseInformation.IsCanaryBuild
? releaseChannels.Canary
: releaseChannels.Stable;
if (_currentGitLabReleaseChannel == null)
{
GitLabReleaseChannels releaseChannels = await GitLabReleaseChannels.GetAsync(jsonClient);
_currentGitLabReleaseChannel = ReleaseInformation.IsCanaryBuild
? releaseChannels.Canary
: releaseChannels.Stable;
_changelogUrlFormat = _currentGitLabReleaseChannel.UrlFormat;
_stableUrlFormat = releaseChannels.Stable.UrlFormat;
}
string fetchedJson = await jsonClient.GetStringAsync(_currentGitLabReleaseChannel.GetLatestReleaseApiUrl());
GitLabReleasesJsonResponse fetched = JsonHelper.Deserialize(fetchedJson, _glSerializerContext.GitLabReleasesJsonResponse);
_buildVer = fetched.TagName;
_buildUrl = fetched.Assets.Links
.FirstOrDefault(link =>
link.AssetName.StartsWith("ryujinx") && link.AssetName.EndsWith(_platformExt)
)?.Url;
// If build not done, assume no new update are available.
if (_buildUrl is null)
{
if (showVersionUpToDate)
{
UserResult userResult = await ContentDialogHelper.CreateUpdaterUpToDateInfoDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterAlreadyOnLatestVersionMessage],
string.Empty);
if (userResult is UserResult.Ok)
{
OpenHelper.OpenUrl(_currentGitLabReleaseChannel.UrlFormat.Format(currentVersion));
}
}
Logger.Info?.Print(LogClass.Application, "Up to date.");
_running = false;
return default;
}
_changelogUrlFormat = _currentGitLabReleaseChannel.UrlFormat;
_stableUrlFormat = releaseChannels.Stable.UrlFormat;
}
catch (Exception exception)
{
Logger.Error?.Print(LogClass.Application, exception.Message);
await ContentDialogHelper.CreateErrorDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterFailedToGetVersionMessage]);
string fetchedJson = await jsonClient.GetStringAsync(_currentGitLabReleaseChannel.GetLatestReleaseApiUrl());
GitLabReleasesJsonResponse fetched = JsonHelper.Deserialize(fetchedJson, _glSerializerContext.GitLabReleasesJsonResponse);
_buildVer = fetched.TagName;
_buildUrl = fetched.Assets.Links
.FirstOrDefault(link =>
link.AssetName.StartsWith("ryujinx") && link.AssetName.EndsWith(_platformExt)
)?.Url;
// If build URL not found, assume no new update are available.
if (_buildUrl is null)
{
if (showVersionUpToDate)
{
UserResult userResult = await ContentDialogHelper.CreateUpdaterUpToDateInfoDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterAlreadyOnLatestVersionMessage],
string.Empty);
if (userResult is UserResult.Ok)
{
OpenHelper.OpenUrl(_currentGitLabReleaseChannel.UrlFormat.Format(currentVersion));
}
}
Logger.Info?.Print(LogClass.Application, "Up to date.");
_running = false;
return default;
}
if (!Version.TryParse(_buildVer, out Version newVersion))
{
Logger.Error?.Print(LogClass.Application, $"Failed to convert the received {RyujinxApp.FullAppName} version from GitHub!");
Logger.Error?.Print(LogClass.Application,
$"Failed to convert the received {RyujinxApp.FullAppName} version from GitLab!");
await ContentDialogHelper.CreateWarningDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedGithubMessage],
@ -113,31 +106,28 @@ namespace Ryujinx.Ava.Systems
return (currentVersion, newVersion);
}
[JsonSerializable(typeof(GitLabReleaseChannels))]
partial class GitLabReleaseChannelPairContext : JsonSerializerContext;
public class GitLabReleaseChannels
{
public static async Task<GitLabReleaseChannels> GetAsync(HttpClient httpClient)
=> await httpClient.GetFromJsonAsync("https://git.ryujinx.app/ryubing/ryujinx/-/snippets/1/raw/main/meta.json", GitLabReleaseChannelPairContext.Default.GitLabReleaseChannels);
public static async Task<GitLabReleaseChannels> GetAsync(HttpClient httpClient)
=> await httpClient.GetFromJsonAsync(
"https://git.ryujinx.app/ryubing/ryujinx/-/snippets/1/raw/main/meta.json",
GitLabReleaseChannelPairContext.Default.GitLabReleaseChannels);
[JsonPropertyName("stable")]
public ChannelType Stable { get; set; }
[JsonPropertyName("canary")]
public ChannelType Canary { get; set; }
[JsonPropertyName("stable")] public ChannelType Stable { get; set; }
[JsonPropertyName("canary")] public ChannelType Canary { get; set; }
public class ChannelType
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("group")]
public string Group { get; set; }
[JsonPropertyName("project")]
public string Project { get; set; }
[JsonPropertyName("id")] public long Id { get; set; }
[JsonPropertyName("group")] public string Group { get; set; }
[JsonPropertyName("project")] public string Project { get; set; }
public string UrlFormat => $"https://git.ryujinx.app/{ToString()}/-/releases/{{0}}";
public override string ToString() => $"{Group}/{Project}";