diff --git a/Iceshrimp.Frontend/Core/Services/UpdateService.cs b/Iceshrimp.Frontend/Core/Services/UpdateService.cs new file mode 100644 index 00000000..3c52487b --- /dev/null +++ b/Iceshrimp.Frontend/Core/Services/UpdateService.cs @@ -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 _logger; + + public UpdateService(ApiService api, ILogger 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 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(); + } + } +} \ No newline at end of file diff --git a/Iceshrimp.Frontend/Startup.cs b/Iceshrimp.Frontend/Startup.cs index 72666ce8..24a2df73 100644 --- a/Iceshrimp.Frontend/Startup.cs +++ b/Iceshrimp.Frontend/Startup.cs @@ -28,6 +28,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();