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 internal static partial class Updater
{ {
private static GitLabReleaseChannels.ChannelType _currentGitLabReleaseChannel; 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)) 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( await ContentDialogHelper.CreateWarningDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedMessage], 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."); Logger.Info?.Print(LogClass.Application, "Checking for updates from https://git.ryujinx.app.");
// Get latest version number from GitLab API // 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) _changelogUrlFormat = _currentGitLabReleaseChannel.UrlFormat;
{ _stableUrlFormat = releaseChannels.Stable.UrlFormat;
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;
}
} }
catch (Exception exception)
{
Logger.Error?.Print(LogClass.Application, exception.Message);
await ContentDialogHelper.CreateErrorDialog( string fetchedJson = await jsonClient.GetStringAsync(_currentGitLabReleaseChannel.GetLatestReleaseApiUrl());
LocaleManager.Instance[LocaleKeys.DialogUpdaterFailedToGetVersionMessage]); 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; _running = false;
return default; return default;
} }
if (!Version.TryParse(_buildVer, out Version newVersion)) 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( await ContentDialogHelper.CreateWarningDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedGithubMessage], LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedGithubMessage],
@ -113,31 +106,28 @@ namespace Ryujinx.Ava.Systems
return (currentVersion, newVersion); return (currentVersion, newVersion);
} }
[JsonSerializable(typeof(GitLabReleaseChannels))] [JsonSerializable(typeof(GitLabReleaseChannels))]
partial class GitLabReleaseChannelPairContext : JsonSerializerContext; partial class GitLabReleaseChannelPairContext : JsonSerializerContext;
public class GitLabReleaseChannels public class GitLabReleaseChannels
{ {
public static async Task<GitLabReleaseChannels> GetAsync(HttpClient httpClient) 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); => await httpClient.GetFromJsonAsync(
"https://git.ryujinx.app/ryubing/ryujinx/-/snippets/1/raw/main/meta.json",
GitLabReleaseChannelPairContext.Default.GitLabReleaseChannels);
[JsonPropertyName("stable")] [JsonPropertyName("stable")] public ChannelType Stable { get; set; }
public ChannelType Stable { get; set; } [JsonPropertyName("canary")] public ChannelType Canary { get; set; }
[JsonPropertyName("canary")]
public ChannelType Canary { get; set; }
public class ChannelType public class ChannelType
{ {
[JsonPropertyName("id")] [JsonPropertyName("id")] public long Id { get; set; }
public long Id { get; set; }
[JsonPropertyName("group")] public string Group { get; set; }
[JsonPropertyName("group")]
public string Group { get; set; } [JsonPropertyName("project")] public string Project { get; set; }
[JsonPropertyName("project")]
public string Project { get; set; }
public string UrlFormat => $"https://git.ryujinx.app/{ToString()}/-/releases/{{0}}"; public string UrlFormat => $"https://git.ryujinx.app/{ToString()}/-/releases/{{0}}";
public override string ToString() => $"{Group}/{Project}"; public override string ToString() => $"{Group}/{Project}";