Fix amiibo timeout issues & log errors/exceptions (#4712)

This commit is contained in:
TSRBerry 2023-04-24 04:08:31 +02:00 committed by GitHub
parent 666e05f5cb
commit c26aeefe03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 11 deletions

View file

@ -7,6 +7,7 @@ using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.Windows; using Ryujinx.Ava.UI.Windows;
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Utilities; using Ryujinx.Common.Utilities;
using Ryujinx.Ui.Common.Models.Amiibo; using Ryujinx.Ui.Common.Models.Amiibo;
using System; using System;
@ -42,13 +43,18 @@ namespace Ryujinx.Ava.UI.ViewModels
private bool _showAllAmiibo; private bool _showAllAmiibo;
private bool _useRandomUuid; private bool _useRandomUuid;
private string _usage; private string _usage;
private static readonly AmiiboJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); private static readonly AmiiboJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
public AmiiboWindowViewModel(StyleableWindow owner, string lastScannedAmiiboId, string titleId) public AmiiboWindowViewModel(StyleableWindow owner, string lastScannedAmiiboId, string titleId)
{ {
_owner = owner; _owner = owner;
_httpClient = new HttpClient { Timeout = TimeSpan.FromMilliseconds(5000) };
_httpClient = new HttpClient
{
Timeout = TimeSpan.FromSeconds(30)
};
LastScannedAmiiboId = lastScannedAmiiboId; LastScannedAmiiboId = lastScannedAmiiboId;
TitleId = titleId; TitleId = titleId;
@ -89,9 +95,7 @@ namespace Ryujinx.Ava.UI.ViewModels
{ {
_showAllAmiibo = value; _showAllAmiibo = value;
#pragma warning disable 4014
ParseAmiiboData(); ParseAmiiboData();
#pragma warning restore 4014
OnPropertyChanged(); OnPropertyChanged();
} }
@ -203,8 +207,10 @@ namespace Ryujinx.Ava.UI.ViewModels
{ {
amiiboJsonString = await DownloadAmiiboJson(); amiiboJsonString = await DownloadAmiiboJson();
} }
catch catch (Exception ex)
{ {
Logger.Error?.Print(LogClass.Application, $"Failed to download amiibo data: {ex}");
ShowInfoDialog(); ShowInfoDialog();
} }
} }
@ -369,8 +375,10 @@ namespace Ryujinx.Ava.UI.ViewModels
return false; return false;
} }
catch catch (Exception ex)
{ {
Logger.Error?.Print(LogClass.Application, $"Failed to check for amiibo updates: {ex}");
ShowInfoDialog(); ShowInfoDialog();
return false; return false;
@ -393,6 +401,8 @@ namespace Ryujinx.Ava.UI.ViewModels
return amiiboJsonString; return amiiboJsonString;
} }
Logger.Error?.Print(LogClass.Application, $"Failed to download amiibo data. Response status code: {response.StatusCode}");
await ContentDialogHelper.CreateInfoDialog(LocaleManager.Instance[LocaleKeys.DialogAmiiboApiTitle], await ContentDialogHelper.CreateInfoDialog(LocaleManager.Instance[LocaleKeys.DialogAmiiboApiTitle],
LocaleManager.Instance[LocaleKeys.DialogAmiiboApiFailFetchMessage], LocaleManager.Instance[LocaleKeys.DialogAmiiboApiFailFetchMessage],
LocaleManager.Instance[LocaleKeys.InputDialogOk], LocaleManager.Instance[LocaleKeys.InputDialogOk],
@ -429,6 +439,10 @@ namespace Ryujinx.Ava.UI.ViewModels
AmiiboImage = bitmap.CreateScaledBitmap(new PixelSize(resizeWidth, resizeHeight)); 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() private void ResetAmiiboPreview()

View file

@ -1,6 +1,7 @@
using Gtk; using Gtk;
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Utilities; using Ryujinx.Common.Utilities;
using Ryujinx.Ui.Common.Configuration; using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Common.Models.Amiibo; using Ryujinx.Ui.Common.Models.Amiibo;
@ -12,7 +13,6 @@ using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using AmiiboApi = Ryujinx.Ui.Common.Models.Amiibo.AmiiboApi; using AmiiboApi = Ryujinx.Ui.Common.Models.Amiibo.AmiiboApi;
using AmiiboJsonSerializerContext = Ryujinx.Ui.Common.Models.Amiibo.AmiiboJsonSerializerContext; using AmiiboJsonSerializerContext = Ryujinx.Ui.Common.Models.Amiibo.AmiiboJsonSerializerContext;
@ -57,7 +57,7 @@ namespace Ryujinx.Ui.Windows
_httpClient = new HttpClient() _httpClient = new HttpClient()
{ {
Timeout = TimeSpan.FromMilliseconds(5000) Timeout = TimeSpan.FromSeconds(30)
}; };
Directory.CreateDirectory(System.IO.Path.Join(AppDataManager.BaseDirPath, "system", "amiibo")); Directory.CreateDirectory(System.IO.Path.Join(AppDataManager.BaseDirPath, "system", "amiibo"));
@ -93,8 +93,10 @@ namespace Ryujinx.Ui.Windows
{ {
amiiboJsonString = await DownloadAmiiboJson(); amiiboJsonString = await DownloadAmiiboJson();
} }
catch catch (Exception ex)
{ {
Logger.Error?.Print(LogClass.Application, $"Failed to download amiibo data: {ex}");
ShowInfoDialog(); ShowInfoDialog();
Close(); Close();
@ -183,8 +185,10 @@ namespace Ryujinx.Ui.Windows
return false; return false;
} }
catch catch (Exception ex)
{ {
Logger.Error?.Print(LogClass.Application, $"Failed to check for amiibo updates: {ex}");
ShowInfoDialog(); ShowInfoDialog();
return false; return false;
@ -208,6 +212,8 @@ namespace Ryujinx.Ui.Windows
} }
else 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."); GtkDialog.CreateInfoDialog($"Amiibo API", "An error occured while fetching information from the API.");
Close(); Close();
@ -233,6 +239,10 @@ namespace Ryujinx.Ui.Windows
_amiiboImage.Pixbuf = amiiboPreview.ScaleSimple(resizeWidth, resizeHeight, Gdk.InterpType.Bilinear); _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() private void ShowInfoDialog()
@ -374,4 +384,4 @@ namespace Ryujinx.Ui.Windows
base.Dispose(disposing); base.Dispose(disposing);
} }
} }
} }