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(); } } }