176 lines
5.8 KiB
Text
176 lines
5.8 KiB
Text
@using LANCommander.Launcher.Models
|
|
@using LANCommander.Launcher.Settings
|
|
@using LANCommander.SDK.Services
|
|
@inject InstallService InstallService
|
|
@inject LibraryService LibraryService
|
|
@inject GameClient GameClient
|
|
@inject SettingsProvider<Settings> SettingsProvider
|
|
@inject NavigationManager NavigationManager
|
|
@inject LocalizationService LocalizationService
|
|
@inject ConfirmService ConfirmService
|
|
@inject ModalService ModalService
|
|
@namespace LANCommander.Launcher.UI
|
|
|
|
<Drawer Placement="DrawerPlacement.Bottom" Class="download-queue" @bind-Visible="@Visible" OnClose="Hide">
|
|
|
|
@if (InstallService.Queue.Any(qi => qi.State))
|
|
{
|
|
<h2>@LocalizationService.GetString("InProgress")</h2>
|
|
@foreach (var queueItem in InstallService.Queue.Where(qi => qi.State))
|
|
{
|
|
<div class="queue-item">
|
|
<MediaImage Id="@queueItem.CoverId" Class="queue-item-cover" />
|
|
<div class="queue-item-info">
|
|
<div>
|
|
<h3>@queueItem.Title</h3>
|
|
</div>
|
|
</div>
|
|
<div class="queue-item-current-download">
|
|
<CurrentDownloadItem />
|
|
</div>
|
|
|
|
<Button Type="ButtonType.Text" Danger Icon="@IconType.Outline.Close" OnClick="() => Cancel(queueItem)" />
|
|
</div>
|
|
}
|
|
}
|
|
|
|
<h2>@LocalizationService.GetString("UpNext")</h2>
|
|
@foreach (var queueItem in InstallService.Queue.Where(qi => !qi.State && qi.Status == SDK.Enums.InstallStatus.Queued))
|
|
{
|
|
<div class="queue-item">
|
|
<MediaImage Id="@queueItem.CoverId" Class="queue-item-cover" />
|
|
<div class="queue-item-info">
|
|
<div>
|
|
<h3>@queueItem.Title</h3>
|
|
</div>
|
|
</div>
|
|
<div class="queue-item-actions">
|
|
<Button Icon="@IconType.Outline.Close" Size="ButtonSize.Large" Danger OnClick="() => Remove(queueItem)" />
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@if (!InstallService.Queue.Any(qi => qi.Status == SDK.Enums.InstallStatus.Queued))
|
|
{
|
|
<Empty Simple Description="@LocalizationService.GetString("TheQueueIsEmpty")" />
|
|
}
|
|
|
|
@if (InstallService.Queue.Any(qi => !qi.State && qi.Status != SDK.Enums.InstallStatus.Queued && qi.Status != SDK.Enums.InstallStatus.Failed && qi.Status != SDK.Enums.InstallStatus.Canceled))
|
|
{
|
|
<h2>@LocalizationService.GetString("Completed")</h2>
|
|
@foreach (var queueItem in InstallService.Queue.Where(qi => !qi.State))
|
|
{
|
|
<div class="queue-item">
|
|
<MediaImage Id="@queueItem.CoverId" Class="queue-item-cover" />
|
|
<div class="queue-item-info">
|
|
<div>
|
|
<h3>@queueItem.Title</h3>
|
|
<span><ByteSize Value="queueItem.TotalBytes" /></span>
|
|
</div>
|
|
</div>
|
|
<div class="queue-item-actions">
|
|
<PlayButton LibraryItemId="@queueItem.Id">
|
|
<MenuExtra>
|
|
<MenuItem OnClick="() => ViewInLibrary(queueItem)">
|
|
@LocalizationService.GetString("ViewInLibrary")
|
|
</MenuItem>
|
|
</MenuExtra>
|
|
</PlayButton>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
</Drawer>
|
|
|
|
@code {
|
|
bool Visible { get; set; } = false;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
InstallService.OnInstallFail += OnInstallFail;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
InstallService.OnQueueChanged += async () =>
|
|
{
|
|
StateHasChanged();
|
|
};
|
|
}
|
|
|
|
async Task Cancel(IInstallQueueItem queueItem)
|
|
{
|
|
await InstallService.CancelInstallAsync(queueItem.Id);
|
|
}
|
|
|
|
async Task Remove(IInstallQueueItem queueItem)
|
|
{
|
|
InstallService.Remove(queueItem);
|
|
}
|
|
|
|
async Task ViewInLibrary(IInstallQueueItem queueItem)
|
|
{
|
|
Visible = false;
|
|
NavigationManager.NavigateTo("/" + queueItem.Id);
|
|
}
|
|
|
|
public async Task Show()
|
|
{
|
|
Visible = true;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
public async Task Hide()
|
|
{
|
|
Visible = false;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task OnInstallFail(Data.Models.Game game)
|
|
{
|
|
var result = await ConfirmService.Show(
|
|
LocalizationService.GetString("InstallationFailedMessage", game.Title),
|
|
LocalizationService.GetString("InstallationFailed"),
|
|
ConfirmButtons.RetryCancel,
|
|
ConfirmIcon.Error
|
|
);
|
|
|
|
await LibraryService.LibraryChanged();
|
|
|
|
if (result == ConfirmResult.Retry)
|
|
{
|
|
var libraryItem = LibraryService.GetItem(game.Id);
|
|
|
|
Install(libraryItem);
|
|
}
|
|
}
|
|
|
|
async Task Install(Models.ListItem libraryItem)
|
|
{
|
|
var addons = await GameClient.GetAddonsAsync(libraryItem.Key);
|
|
|
|
if (SettingsProvider.CurrentValue.Games.InstallDirectories.Length > 1 || (addons != null && addons.Any()))
|
|
{
|
|
var modalOptions = new ModalOptions
|
|
{
|
|
Title = LocalizationService.GetString("InstallGame", libraryItem.Name),
|
|
Maximizable = false,
|
|
DefaultMaximized = false,
|
|
Closable = true,
|
|
OkText = LocalizationService.GetString("Install"),
|
|
Draggable = true,
|
|
Centered = true,
|
|
WrapClassName = "ant-modal-wrap-no-padding",
|
|
Footer = null,
|
|
};
|
|
|
|
var modalRef = ModalService.CreateModal<InstallDialog, Models.ListItem, string>(modalOptions, libraryItem);
|
|
}
|
|
else
|
|
{
|
|
await InstallService.Add(libraryItem.DataItem as Data.Models.Game);
|
|
}
|
|
}
|
|
}
|