@using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Frontend.Localization @using Microsoft.Extensions.Localization @inject UpdateService UpdateSvc; @inject IJSRuntime Js; @inject IStringLocalizer Loc; @inject NavigationManager Nav; @implements IDisposable
@Loc["Update required!"]
Iceshrimp.NET @UpdateSvc.BackendVersion?.Version Codename @UpdateSvc.BackendVersion?.Codename @if (UpdateSvc.BackendVersion?.CommitHash != null) { Commit @UpdateSvc.BackendVersion?.CommitHash }
@Loc["Reloading..."] @Loc["Switch to new version"] @Loc["Update loading"] @Loc["Failed to install update"]
@code { private ElementReference Dialog { get; set; } private IJSObjectReference _module = null!; private StateButton UpdateButton { get; set; } = null!; private void OnUpdateStatusChange(object? _, UpdateService.UpdateStates newState) { if (newState != UpdateService.UpdateStates.NoUpdate) { OpenDialog(); } if (newState == UpdateService.UpdateStates.UpdateInstalling) UpdateButton.State = StateButton.StateEnum.Loading; if (newState == UpdateService.UpdateStates.UpdateInstalled) UpdateButton.State = StateButton.StateEnum.Initial; StateHasChanged(); } private void CloseDialog() { var module = (IJSInProcessObjectReference)_module; module.InvokeVoid("closeDialog", Dialog); } private void OpenDialog() { var module = (IJSInProcessObjectReference)_module; module.InvokeVoid("openDialog", Dialog); } protected override async Task OnInitializedAsync() { _module = await Js.InvokeAsync("import", "./Components/UpdateNotice.razor.js"); UpdateSvc.UpdateStatusEvent += OnUpdateStatusChange; await UpdateSvc.ServiceWorkerUpdateAsync(); } public void Dispose() { UpdateSvc.UpdateStatusEvent -= OnUpdateStatusChange; } private async Task SwitchVersion() { if (UpdateSvc.UpdateState == UpdateService.UpdateStates.UpdateInstalled) { await UpdateSvc.ServiceWorkerSkipWaitingAsync(); Nav.NavigateTo("/", true); } } }