[frontend/core] Add settings service
This commit is contained in:
parent
b2b206f065
commit
ed11602158
2 changed files with 36 additions and 0 deletions
35
Iceshrimp.Frontend/Core/Services/SettingsService.cs
Normal file
35
Iceshrimp.Frontend/Core/Services/SettingsService.cs
Normal file
|
@ -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<SettingsService> logger)
|
||||
{
|
||||
private UserSettingsResponse? UserSettings { get; set; }
|
||||
|
||||
public async Task<UserSettingsResponse> 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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ builder.Services.AddSingleton<VersionService>();
|
|||
builder.Services.AddSingleton<MessageService>();
|
||||
builder.Services.AddSingleton<GlobalComponentSvc>();
|
||||
builder.Services.AddSingleton<UpdateService>();
|
||||
builder.Services.AddSingleton<SettingsService>();
|
||||
builder.Services.AddAuthorizationCore();
|
||||
builder.Services.AddCascadingAuthenticationState();
|
||||
builder.Services.AddBlazoredLocalStorageAsSingleton();
|
||||
|
|
Loading…
Add table
Reference in a new issue