* more cancellation tokens and fixes * so much cancellation token * fix mysql playout builds
81 lines
3.1 KiB
Plaintext
81 lines
3.1 KiB
Plaintext
@page "/settings/scanner"
|
|
@using ErsatzTV.Application.Configuration
|
|
@implements IDisposable
|
|
@inject IMediator Mediator
|
|
@inject ISnackbar Snackbar
|
|
@inject ILogger<ScannerSettings> Logger
|
|
|
|
<MudForm @ref="_form" @bind-IsValid="@_scannerSuccess" Style="max-height: 100%">
|
|
<MudPaper Square="true" Style="display: flex; height: 64px; min-height: 64px; width: 100%; z-index: 100; align-items: center">
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(_ => SaveScannerSettings())" Class="ml-6" StartIcon="@Icons.Material.Filled.Save">Save Settings</MudButton>
|
|
</MudPaper>
|
|
<div class="d-flex flex-column" style="height: 100vh; overflow-x: auto">
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<MudText Typo="Typo.h5" Class="mb-2">Scanner</MudText>
|
|
<MudDivider Class="mb-6"/>
|
|
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
|
|
<div class="d-flex">
|
|
<MudText>Library Refresh Interval</MudText>
|
|
</div>
|
|
<MudTextField @bind-Value="_libraryRefreshInterval" Validation="@(new Func<int, string>(ValidateLibraryRefreshInterval))" Required="true" RequiredError="Library refresh interval is required!" Adornment="Adornment.End" AdornmentText="hours"/>
|
|
</MudStack>
|
|
</MudContainer>
|
|
</div>
|
|
</MudForm>
|
|
|
|
@code {
|
|
private CancellationTokenSource _cts;
|
|
|
|
private MudForm _form;
|
|
private bool _scannerSuccess;
|
|
private int _libraryRefreshInterval;
|
|
|
|
public void Dispose()
|
|
{
|
|
_cts?.Cancel();
|
|
_cts?.Dispose();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_cts?.Cancel();
|
|
_cts?.Dispose();
|
|
_cts = new CancellationTokenSource();
|
|
var token = _cts.Token;
|
|
|
|
try
|
|
{
|
|
_libraryRefreshInterval = await Mediator.Send(new GetLibraryRefreshInterval(), token);
|
|
_scannerSuccess = _libraryRefreshInterval is >= 0 and < 1_000_000;
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
// do nothing
|
|
}
|
|
}
|
|
|
|
private static string ValidateLibraryRefreshInterval(int libraryRefreshInterval) => libraryRefreshInterval switch
|
|
{
|
|
<= -1 => "Library refresh interval must be 0 (do not refresh) or greater than zero",
|
|
>= 1_000_000 => "Library refresh interval must be less than 1,000,000. Use 0 to disable automatic refresh",
|
|
_ => null
|
|
};
|
|
|
|
private async Task SaveScannerSettings()
|
|
{
|
|
await _form.Validate();
|
|
if (_scannerSuccess)
|
|
{
|
|
Either<BaseError, Unit> result = await Mediator.Send(new UpdateLibraryRefreshInterval(_libraryRefreshInterval), _cts.Token);
|
|
result.Match(
|
|
Left: error =>
|
|
{
|
|
Snackbar.Add(error.Value, Severity.Error);
|
|
Logger.LogError("Unexpected error saving scanner settings: {Error}", error.Value);
|
|
},
|
|
Right: _ => Snackbar.Add("Successfully saved scanner settings", Severity.Success));
|
|
}
|
|
}
|
|
|
|
}
|