test
This commit is contained in:
parent
fa1590512f
commit
f3c82e3f05
2 changed files with 49 additions and 0 deletions
48
Iceshrimp.Frontend/Core/Services/UpdateService.cs
Normal file
48
Iceshrimp.Frontend/Core/Services/UpdateService.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ builder.Services.AddSingleton<EmojiService>();
|
||||||
builder.Services.AddSingleton<VersionService>();
|
builder.Services.AddSingleton<VersionService>();
|
||||||
builder.Services.AddSingleton<MessageService>();
|
builder.Services.AddSingleton<MessageService>();
|
||||||
builder.Services.AddSingleton<GlobalComponentSvc>();
|
builder.Services.AddSingleton<GlobalComponentSvc>();
|
||||||
|
builder.Services.AddSingleton<UpdateService>();
|
||||||
builder.Services.AddAuthorizationCore();
|
builder.Services.AddAuthorizationCore();
|
||||||
builder.Services.AddCascadingAuthenticationState();
|
builder.Services.AddCascadingAuthenticationState();
|
||||||
builder.Services.AddBlazoredLocalStorageAsSingleton();
|
builder.Services.AddBlazoredLocalStorageAsSingleton();
|
||||||
|
|
Loading…
Add table
Reference in a new issue