This commit is contained in:
Lilian 2024-11-06 01:07:54 +01:00
parent fa1590512f
commit f3c82e3f05
No known key found for this signature in database
2 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,48 @@
using System.Timers;
using Iceshrimp.Frontend.Core.Miscellaneous;
using Iceshrimp.Shared.Helpers;
using Iceshrimp.Shared.Schemas.Web;
using Timer = System.Timers.Timer;
namespace Iceshrimp.Frontend.Core.Services;
internal class UpdateService
{
private readonly ApiService _api;
private readonly ILogger<UpdateService> _logger;
public UpdateService(ApiService api, ILogger<UpdateService> logger)
{
_api = api;
_logger = logger;
UpdateTimer = new Timer { AutoReset = true, Enabled = true, Interval = 60000, };
UpdateTimer.Elapsed += (_, _) => CheckVersion();
}
private VersionInfo FrontendVersion { get; } = VersionHelpers.GetVersionInfo();
private Timer UpdateTimer { get; }
private async Task<VersionResponse?> GetVersion()
{
try
{
var backendVersion = await _api.Version.GetVersion();
return backendVersion;
}
catch (ApiException e)
{
_logger.LogError(e, "Failed to fetch version.");
return null;
}
}
private async void CheckVersion()
{
var version = await GetVersion();
if (version is null) return;
if (version.Version != FrontendVersion.Version)
{
throw new NotImplementedException();
}
}
}

View file

@ -28,6 +28,7 @@ builder.Services.AddSingleton<EmojiService>();
builder.Services.AddSingleton<VersionService>();
builder.Services.AddSingleton<MessageService>();
builder.Services.AddSingleton<GlobalComponentSvc>();
builder.Services.AddSingleton<UpdateService>();
builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddBlazoredLocalStorageAsSingleton();