LANCommander/LANCommander.Launcher/UI/Components/DownloadQueue/CurrentDownloadItem.razor
Pat Hartl 698a7523b6 Code cleanup
- Move all Launcher components to LANCommander.Launcher.UI namespace
- Move all SCSS files next to components (when possible)
- Refactor styles that control overflow of content into titlebar to MainWindow only
- Remove use in launcher UI of SDK.Client
2025-12-31 20:01:04 -06:00

113 lines
3.9 KiB
Text

@using LANCommander.Launcher.Models
@using LANCommander.SDK.Enums
@namespace LANCommander.Launcher.UI
@inject InstallService InstallService
@inject LocalizationService LocalizationService
@if (CurrentQueueItem != null)
{
<div class="downloader-current">
@if (ShowIcon)
{
<div class="downloader-current-icon">
<MediaImage Id="@Progress.IconId" />
</div>
}
<div class="downloader-current-info">
<div class="downloader-current-upper">
<div class="downloader-current-upper-status">
@if (Progress.Status == SDK.Enums.InstallStatus.Downloading && Progress.Progress > 0)
{
<Text>@Progress.Status.GetDisplayName() @Progress.Title: @Progress.Progress.ToString("0%")</Text>
}
else
{
<Text>@Progress.Status.GetDisplayName()</Text>
}
</div>
@if (Progress.TransferSpeed > 0)
{
<div class="downloader-current-upper-time-remaining">
@Progress.TimeRemaining.ToString(@"hh\:mm\:ss")
</div>
}
</div>
<div class="downloader-current-progress">
<Progress Percent="(Progress.Progress * 100)"/>
</div>
<div class="downloader-current-lower">
<div class="downloader-current-lower-data">
@if (Progress.Status == InstallStatus.Canceled)
{
LocalizationService.GetString("Cancelling");
}
else
{
<Text>
<ByteSize Value="Progress.BytesTransferred"/> / <ByteSize Value="Progress.TotalBytes"/>
</Text>
}
</div>
<div class="downloader-current-lower-speed">
<ByteSize Value="Progress.TransferSpeed" />/s
</div>
</div>
</div>
</div>
}
@code {
[Parameter] public bool ShowIcon { get; set; }
[Parameter] public IInstallQueueItem? CurrentQueueItem { get; set; }
[Parameter] public EventCallback<IInstallQueueItem> CurrentQueueItemChanged { get; set; }
InstallProgress Progress = new();
protected override async Task OnInitializedAsync()
{
InstallService.OnProgress += async (progress) =>
{
Progress = progress;
if (Progress.Status == InstallStatus.Canceled)
{
Progress.TransferSpeed = 0;
Progress.Progress = 1;
Progress.Indeterminate = true;
}
if (Progress.Progress < 0)
Progress.Progress = 0;
await InvokeAsync(StateHasChanged);
await Task.Yield();
};
InstallService.OnQueueChanged += async () =>
{
var activeQueueItem = InstallService.Queue.OrderByDescending(qi => qi.QueuedOn).FirstOrDefault(qi => qi.State);
if (activeQueueItem == null)
{
CurrentQueueItem = null;
if (CurrentQueueItemChanged.HasDelegate)
await CurrentQueueItemChanged.InvokeAsync(CurrentQueueItem);
await InvokeAsync(StateHasChanged);
await Task.Yield();
return;
}
if (CurrentQueueItem == null || CurrentQueueItem.Id != activeQueueItem.Id)
{
CurrentQueueItem = activeQueueItem;
if (CurrentQueueItemChanged.HasDelegate)
await CurrentQueueItemChanged.InvokeAsync(CurrentQueueItem);
await InvokeAsync(StateHasChanged);
await Task.Yield();
}
};
}
}