From c26aeefe039ff819f79196623a7e94a1908b7add Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Mon, 24 Apr 2023 04:08:31 +0200 Subject: [PATCH] Fix amiibo timeout issues & log errors/exceptions (#4712) --- .../UI/ViewModels/AmiiboWindowViewModel.cs | 26 ++++++++++++++----- Ryujinx/Ui/Windows/AmiiboWindow.cs | 20 ++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs b/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs index 090c13a97..bb92798fa 100644 --- a/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs +++ b/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs @@ -7,6 +7,7 @@ using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Windows; using Ryujinx.Common; using Ryujinx.Common.Configuration; +using Ryujinx.Common.Logging; using Ryujinx.Common.Utilities; using Ryujinx.Ui.Common.Models.Amiibo; using System; @@ -42,13 +43,18 @@ namespace Ryujinx.Ava.UI.ViewModels private bool _showAllAmiibo; private bool _useRandomUuid; private string _usage; - + private static readonly AmiiboJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); public AmiiboWindowViewModel(StyleableWindow owner, string lastScannedAmiiboId, string titleId) { _owner = owner; - _httpClient = new HttpClient { Timeout = TimeSpan.FromMilliseconds(5000) }; + + _httpClient = new HttpClient + { + Timeout = TimeSpan.FromSeconds(30) + }; + LastScannedAmiiboId = lastScannedAmiiboId; TitleId = titleId; @@ -89,9 +95,7 @@ namespace Ryujinx.Ava.UI.ViewModels { _showAllAmiibo = value; -#pragma warning disable 4014 ParseAmiiboData(); -#pragma warning restore 4014 OnPropertyChanged(); } @@ -203,8 +207,10 @@ namespace Ryujinx.Ava.UI.ViewModels { amiiboJsonString = await DownloadAmiiboJson(); } - catch + catch (Exception ex) { + Logger.Error?.Print(LogClass.Application, $"Failed to download amiibo data: {ex}"); + ShowInfoDialog(); } } @@ -369,8 +375,10 @@ namespace Ryujinx.Ava.UI.ViewModels return false; } - catch + catch (Exception ex) { + Logger.Error?.Print(LogClass.Application, $"Failed to check for amiibo updates: {ex}"); + ShowInfoDialog(); return false; @@ -393,6 +401,8 @@ namespace Ryujinx.Ava.UI.ViewModels return amiiboJsonString; } + Logger.Error?.Print(LogClass.Application, $"Failed to download amiibo data. Response status code: {response.StatusCode}"); + await ContentDialogHelper.CreateInfoDialog(LocaleManager.Instance[LocaleKeys.DialogAmiiboApiTitle], LocaleManager.Instance[LocaleKeys.DialogAmiiboApiFailFetchMessage], LocaleManager.Instance[LocaleKeys.InputDialogOk], @@ -429,6 +439,10 @@ namespace Ryujinx.Ava.UI.ViewModels AmiiboImage = bitmap.CreateScaledBitmap(new PixelSize(resizeWidth, resizeHeight)); } } + else + { + Logger.Error?.Print(LogClass.Application, $"Failed to get amiibo preview. Response status code: {response.StatusCode}"); + } } private void ResetAmiiboPreview() diff --git a/Ryujinx/Ui/Windows/AmiiboWindow.cs b/Ryujinx/Ui/Windows/AmiiboWindow.cs index 470032373..11a566d8d 100644 --- a/Ryujinx/Ui/Windows/AmiiboWindow.cs +++ b/Ryujinx/Ui/Windows/AmiiboWindow.cs @@ -1,6 +1,7 @@ using Gtk; using Ryujinx.Common; using Ryujinx.Common.Configuration; +using Ryujinx.Common.Logging; using Ryujinx.Common.Utilities; using Ryujinx.Ui.Common.Configuration; using Ryujinx.Ui.Common.Models.Amiibo; @@ -12,7 +13,6 @@ using System.Linq; using System.Net.Http; using System.Reflection; using System.Text; -using System.Text.Json; using System.Threading.Tasks; using AmiiboApi = Ryujinx.Ui.Common.Models.Amiibo.AmiiboApi; using AmiiboJsonSerializerContext = Ryujinx.Ui.Common.Models.Amiibo.AmiiboJsonSerializerContext; @@ -57,7 +57,7 @@ namespace Ryujinx.Ui.Windows _httpClient = new HttpClient() { - Timeout = TimeSpan.FromMilliseconds(5000) + Timeout = TimeSpan.FromSeconds(30) }; Directory.CreateDirectory(System.IO.Path.Join(AppDataManager.BaseDirPath, "system", "amiibo")); @@ -93,8 +93,10 @@ namespace Ryujinx.Ui.Windows { amiiboJsonString = await DownloadAmiiboJson(); } - catch + catch (Exception ex) { + Logger.Error?.Print(LogClass.Application, $"Failed to download amiibo data: {ex}"); + ShowInfoDialog(); Close(); @@ -183,8 +185,10 @@ namespace Ryujinx.Ui.Windows return false; } - catch + catch (Exception ex) { + Logger.Error?.Print(LogClass.Application, $"Failed to check for amiibo updates: {ex}"); + ShowInfoDialog(); return false; @@ -208,6 +212,8 @@ namespace Ryujinx.Ui.Windows } else { + Logger.Error?.Print(LogClass.Application, $"Failed to download amiibo data. Response status code: {response.StatusCode}"); + GtkDialog.CreateInfoDialog($"Amiibo API", "An error occured while fetching information from the API."); Close(); @@ -233,6 +239,10 @@ namespace Ryujinx.Ui.Windows _amiiboImage.Pixbuf = amiiboPreview.ScaleSimple(resizeWidth, resizeHeight, Gdk.InterpType.Bilinear); } + else + { + Logger.Error?.Print(LogClass.Application, $"Failed to get amiibo preview. Response status code: {response.StatusCode}"); + } } private void ShowInfoDialog() @@ -374,4 +384,4 @@ namespace Ryujinx.Ui.Windows base.Dispose(disposing); } } -} +} \ No newline at end of file