Iceshrimp.NET/Iceshrimp.Frontend/Pages/Settings/About.razor

151 lines
No EOL
4.9 KiB
Text

@page "/settings/about"
@using System.Text
@using Iceshrimp.Assets.PhosphorIcons
@using Iceshrimp.Frontend.Core.InMemoryLogger
@using Iceshrimp.Frontend.Core.Services
@using Iceshrimp.Frontend.Localization
@using Iceshrimp.Shared.Schemas.Web
@using Microsoft.AspNetCore.Authorization
@using Microsoft.Extensions.Localization
@using Microsoft.AspNetCore.Components.Sections
@attribute [Authorize]
@layout SettingsLayout;
@inject VersionService Version;
@inject IStringLocalizer<Localization> Loc;
@inject IJSRuntime Js;
@inject InMemoryLogService LogSvc;
@inject UpdateService UpdateSvc;
@inject NavigationManager Nav;
@inject ILogger<About> Logger;
<SectionContent SectionName="top-bar">
<Icon Name="Icons.Info"></Icon>
@Loc["About"]
</SectionContent>
<div class="body">
<div class="version">
<h1>@Loc["Version Information"]</h1>
<span class="name">Iceshrimp.NET</span>
<span class="value">
<code>@Version.Version</code>
</span>
<span class="name">Codename</span>
<span class="value">
<code>@Version.Codename</code>
</span>
@if (Version.CommitHash != null)
{
<span class="name">Commit</span>
<span class="value">
<code>@Version.CommitHash</code>
</span>
}
<span class="name">.NET Runtime</span>
<span class="value">
<code>@Environment.Version</code>
</span>
</div>
<div class="update">
<button class="button" @onclick="@CheckUpdate">@Loc["Check for updates"]</button>
@if (_updateAvailable == CheckState.True)
{
<div>New version!</div>
<div class="version">
<span class="name">Iceshrimp.NET</span>
<span class="value">
<code>@_newVersion?.Version</code>
</span>
<span class="name">Codename</span>
<span class="value">
<code>@_newVersion?.Codename</code>
</span>
@if (_newVersion?.CommitHash != null)
{
<span class="name">Commit</span>
<span class="value">
<code>@_newVersion?.CommitHash</code>
</span>
}
</div>
<button class="button" @onclick="@SkipWaiting">@Loc["Load new version"]</button>
@if (_skipWaitingRes == CheckState.Error)
{
<div>@Loc["Something went wrong while loading the update, please check the logs."]</div>
}
}
@if (_updateAvailable == CheckState.False)
{
<div>@Loc["Already on the newest version!"]</div>
}
@if (_updateAvailable == CheckState.Error)
{
<div>@Loc["Failed to check for updates."]</div>
}
</div>
<div class="logs">
<h1>@Loc["Logs"]</h1>
@Loc["These logs may contain sensitive information, please do not post them publicly.\n" + "Providing them to developers upon request may help with debugging."]
<button class="button" @onclick="DownloadLogs">
<Icon Name="Icons.DownloadSimple"/>
<span>@Loc["Download Logs"]</span></button>
</div>
</div>
@code {
private IJSInProcessObjectReference _module = null!;
private CheckState _updateAvailable = CheckState.Unknown;
private CheckState _skipWaitingRes = CheckState.Unknown;
private VersionResponse? _newVersion;
protected override async Task OnInitializedAsync()
{
_module = (IJSInProcessObjectReference)await Js.InvokeAsync<IJSObjectReference>("import", "./Components/ErrorUi.razor.js");
await CheckUpdate();
}
private enum CheckState
{
Unknown,
True,
False,
Error
}
private async Task CheckUpdate()
{
try
{
await UpdateSvc.ServiceWorkerUpdateAsync();
}
catch (Exception e)
{
Logger.LogError(e, "Failed to check for updates.");
_updateAvailable = CheckState.Error;
return;
}
var res = await UpdateSvc.ServiceWorkerCheckWaitingAsync();
_updateAvailable = res ? CheckState.True : CheckState.False;
_newVersion = UpdateSvc.BackendVersion;
StateHasChanged();
}
private async Task SkipWaiting()
{
var res = await UpdateSvc.ServiceWorkerSkipWaitingAsync();
_skipWaitingRes = res ? CheckState.True : CheckState.Error;
if (res)
{
Nav.NavigateTo("/", true);
}
}
private void DownloadLogs()
{
var logBytes = LogSvc.GetLogs().SelectMany(p => Encoding.UTF8.GetBytes(p)).ToArray();
_module.InvokeVoid("DownloadFile", "log.txt", "text/plain", logBytes);
}
}