diff --git a/Iceshrimp.Frontend/Core/Services/SettingsService.cs b/Iceshrimp.Frontend/Core/Services/SettingsService.cs new file mode 100644 index 00000000..02882679 --- /dev/null +++ b/Iceshrimp.Frontend/Core/Services/SettingsService.cs @@ -0,0 +1,35 @@ +using Iceshrimp.Frontend.Core.Miscellaneous; +using Iceshrimp.Shared.Schemas.Web; + +namespace Iceshrimp.Frontend.Core.Services; + +internal class SettingsService(ApiService api, ILogger logger) +{ + private UserSettingsResponse? UserSettings { get; set; } + + public async Task GetUserSettingsAsync() + { + if (UserSettings is null) + { + while (UserSettings is null) + { + await UpdateUserSettingsAsync(); + } + } + + _ = UpdateUserSettingsAsync(); + return UserSettings; + } + + private async Task UpdateUserSettingsAsync() + { + try + { + UserSettings = await api.Settings.GetSettingsAsync(); + } + catch (ApiException e) + { + logger.LogError(e, "Failed to fetch settings"); + } + } +} diff --git a/Iceshrimp.Frontend/Startup.cs b/Iceshrimp.Frontend/Startup.cs index c1ddc05e..47f60354 100644 --- a/Iceshrimp.Frontend/Startup.cs +++ b/Iceshrimp.Frontend/Startup.cs @@ -30,6 +30,7 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddAuthorizationCore(); builder.Services.AddCascadingAuthenticationState(); builder.Services.AddBlazoredLocalStorageAsSingleton();