LANCommander/LANCommander.Client/UI/Components/Footer.razor
2024-06-07 17:39:13 -05:00

80 lines
2.3 KiB
Text

@using LANCommander.Client.Models
@using System.Diagnostics
@inject DownloadService DownloadService
@inject SDK.Client Client
<footer>
<Space Direction="DirectionVHType.Horizontal" Class="downloader" Style="width: 100%">
<SpaceItem Style="flex-grow: 1">
@if (CurrentQueueItem != null)
{
<div>@CurrentQueueItem.Title</div>
<div>@CurrentQueueItem.Version</div>
<Progress Percent="(CurrentQueueItem.Progress * 100)" />
}
else
{
<div>Fallout 3</div>
<div>v1.0.0</div>
<Progress Percent="56" />
}
</SpaceItem>
<SpaceItem>
<Button Type="@ButtonType.Primary" OnClick="() => ShowDownloadQueue()">^</Button>
</SpaceItem>
</Space>
</footer>
<DownloadQueue @bind-Visible="@DownloadQueueVisible" />
@code {
IDownloadQueueItem CurrentQueueItem = null;
bool DownloadQueueVisible = false;
Stopwatch Stopwatch = new Stopwatch();
protected override async Task OnInitializedAsync()
{
Client.Games.OnArchiveExtractionProgress += (long position, long length, SDK.Models.Game game) =>
{
if (!Stopwatch.IsRunning)
Stopwatch.Start();
if (Stopwatch.ElapsedMilliseconds > 500)
{
CurrentQueueItem = DownloadService.Queue.OrderByDescending(qi => qi.QueuedOn).FirstOrDefault(qi => qi.State);
CurrentQueueItem.BytesDownloaded = position;
CurrentQueueItem.TotalBytes = length;
InvokeAsync(StateHasChanged);
Stopwatch.Reset();
}
};
Client.Games.OnArchiveEntryExtractionProgress += (object sender, SDK.ArchiveEntryExtractionProgressArgs e) =>
{
// InvokeAsync(StateHasChanged);
};
DownloadService.OnInstallComplete += async () =>
{
Stopwatch.Stop();
};
DownloadService.OnQueueChanged += async () =>
{
CurrentQueueItem = DownloadService.Queue.OrderByDescending(qi => qi.QueuedOn).FirstOrDefault(qi => qi.State);
InvokeAsync(StateHasChanged);
};
}
async Task ShowDownloadQueue()
{
DownloadQueueVisible = true;
}
}