2024-07-15 19:47:32 -05:00
|
|
|
@implements IDisposable
|
2024-08-04 17:53:19 -05:00
|
|
|
@using LANCommander.Launcher.Data.Models
|
|
|
|
|
@using LANCommander.Launcher.Models
|
2024-06-10 23:29:19 -05:00
|
|
|
@using System.Diagnostics
|
|
|
|
|
@using LANCommander.SDK.Helpers
|
2024-08-26 20:18:54 -05:00
|
|
|
@inject SDK.Client Client
|
2024-06-10 23:29:19 -05:00
|
|
|
@inject GameService GameService
|
|
|
|
|
@inject LibraryService LibraryService
|
2024-10-26 15:48:47 -05:00
|
|
|
@inject InstallService InstallService
|
2024-06-10 23:29:19 -05:00
|
|
|
@inject ModalService ModalService
|
2024-08-01 17:27:35 -05:00
|
|
|
@inject MessageService MessageService
|
2024-07-11 18:32:09 -05:00
|
|
|
@inject MessageBusService MessageBusService
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
@inject LocalizationService LocalizationService
|
2024-06-10 23:29:19 -05:00
|
|
|
|
2025-01-12 21:49:30 -06:00
|
|
|
@if (State == PlayButtonState.Running)
|
2024-06-10 23:29:19 -05:00
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Popconfirm Title="@LocalizationService.GetString("DoYouWantToStopGame")" OkText="@LocalizationService.GetString("Yes")" OnConfirm="() => Stop()">
|
|
|
|
|
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Icon="@IconType.Outline.CaretRight">@LocalizationService.GetString("Running")</Button>
|
2024-06-10 23:29:19 -05:00
|
|
|
</Popconfirm>
|
|
|
|
|
}
|
2025-01-12 21:49:30 -06:00
|
|
|
else if (State == PlayButtonState.Starting)
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Loading="true">@LocalizationService.GetString("Starting")</Button>
|
2025-01-12 21:49:30 -06:00
|
|
|
}
|
|
|
|
|
else if (State == PlayButtonState.Stopping)
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Loading="true">@LocalizationService.GetString("Stopping")</Button>
|
2025-01-12 21:49:30 -06:00
|
|
|
}
|
2024-06-10 23:29:19 -05:00
|
|
|
else
|
|
|
|
|
{
|
2024-12-31 18:21:41 -06:00
|
|
|
<Space Direction="SpaceDirection.Horizontal">
|
2024-06-10 23:29:19 -05:00
|
|
|
<SpaceItem>
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Icon="@IconType.Outline.CaretRight" OnClick="() => Run()">@LocalizationService.GetString("Play")</Button>
|
2024-06-10 23:29:19 -05:00
|
|
|
</SpaceItem>
|
|
|
|
|
|
|
|
|
|
<SpaceItem>
|
|
|
|
|
<Dropdown>
|
|
|
|
|
<Overlay>
|
|
|
|
|
<Menu>
|
2024-08-01 17:21:44 -05:00
|
|
|
<LibraryItemContextMenu Model="LibraryItem" MenuExtra="MenuExtra" />
|
2024-06-10 23:29:19 -05:00
|
|
|
</Menu>
|
|
|
|
|
</Overlay>
|
|
|
|
|
|
|
|
|
|
<ChildContent>
|
2024-12-31 18:21:41 -06:00
|
|
|
<Button Type="@ButtonType.Default" Size="ButtonSize.Large" Icon="@IconType.Outline.Ellipsis" />
|
2024-06-10 23:29:19 -05:00
|
|
|
</ChildContent>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</SpaceItem>
|
|
|
|
|
</Space>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@code {
|
2024-08-01 17:21:44 -05:00
|
|
|
[Parameter] public Guid LibraryItemId { get; set; }
|
2024-11-09 17:15:04 -06:00
|
|
|
[Parameter] public Models.ListItem LibraryItem { get; set; }
|
2024-06-11 00:10:19 -05:00
|
|
|
[Parameter] public RenderFragment MenuExtra { get; set; }
|
2024-06-10 23:29:19 -05:00
|
|
|
|
2024-08-26 20:18:54 -05:00
|
|
|
Timer StateTimer;
|
2024-07-15 19:47:32 -05:00
|
|
|
Settings Settings;
|
2025-01-12 21:49:30 -06:00
|
|
|
PlayButtonState State = PlayButtonState.Idle;
|
|
|
|
|
|
|
|
|
|
public enum PlayButtonState
|
|
|
|
|
{
|
|
|
|
|
Idle,
|
|
|
|
|
Starting,
|
|
|
|
|
Running,
|
|
|
|
|
Stopping
|
|
|
|
|
}
|
2024-07-15 19:47:32 -05:00
|
|
|
|
2024-07-11 18:32:09 -05:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2024-08-26 20:18:54 -05:00
|
|
|
StateTimer = new Timer(state => { InvokeAsync(UpdateState); }, null, 0, 250);
|
2024-07-15 19:47:32 -05:00
|
|
|
Settings = SettingService.GetSettings();
|
2024-07-11 18:32:09 -05:00
|
|
|
}
|
|
|
|
|
|
2024-06-10 23:29:19 -05:00
|
|
|
protected override async Task OnParametersSetAsync()
|
|
|
|
|
{
|
2024-08-01 17:21:44 -05:00
|
|
|
if (LibraryItem == null && LibraryItemId != Guid.Empty)
|
2024-11-09 17:15:04 -06:00
|
|
|
LibraryItem = await LibraryService.GetItemAsync(LibraryItemId);
|
2024-06-10 23:29:19 -05:00
|
|
|
}
|
|
|
|
|
|
2024-08-26 20:18:54 -05:00
|
|
|
async Task UpdateState()
|
2024-07-11 18:32:09 -05:00
|
|
|
{
|
2025-01-12 21:49:30 -06:00
|
|
|
if (Client.Games.IsRunning(LibraryItem.Key))
|
2024-08-26 20:18:54 -05:00
|
|
|
{
|
2025-01-12 21:49:30 -06:00
|
|
|
await ChangeState(PlayButtonState.Running);
|
2024-08-26 20:18:54 -05:00
|
|
|
}
|
2025-01-12 21:49:30 -06:00
|
|
|
else if (State == PlayButtonState.Running && !Client.Games.IsRunning(LibraryItem.Key))
|
2024-07-11 18:32:09 -05:00
|
|
|
{
|
2025-01-12 21:49:30 -06:00
|
|
|
await ChangeState(PlayButtonState.Idle);
|
2024-07-11 18:32:09 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 21:49:30 -06:00
|
|
|
async Task ChangeState(PlayButtonState state)
|
|
|
|
|
{
|
|
|
|
|
State = state;
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 23:29:19 -05:00
|
|
|
async Task Run()
|
|
|
|
|
{
|
2024-08-01 17:21:44 -05:00
|
|
|
var game = LibraryItem.DataItem as Game;
|
2025-02-28 14:02:27 -06:00
|
|
|
|
2024-09-05 00:48:04 -05:00
|
|
|
var actions = await Client.Games.GetActionsAsync(game.InstallDirectory, game.Id);
|
2024-06-10 23:29:19 -05:00
|
|
|
|
2025-01-12 21:49:30 -06:00
|
|
|
await ChangeState(PlayButtonState.Starting);
|
|
|
|
|
|
2024-08-01 17:27:35 -05:00
|
|
|
if (actions == null || actions.Count() == 0)
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
MessageService.Error(LocalizationService.GetString("NoActionsFound"));
|
2025-01-12 21:49:30 -06:00
|
|
|
|
|
|
|
|
await ChangeState(PlayButtonState.Idle);
|
2024-08-01 17:27:35 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 17:29:32 -06:00
|
|
|
var primaryActions = actions.Where(a => a.IsPrimaryAction && (LibraryService.IsInstalled(a.GameId) || a.GameId == Guid.Empty));
|
2024-06-10 23:29:19 -05:00
|
|
|
|
2024-08-01 17:27:35 -05:00
|
|
|
if (primaryActions.Count() == 0)
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
MessageService.Error(LocalizationService.GetString("NoPrimaryActionFound"));
|
2025-01-12 21:49:30 -06:00
|
|
|
|
|
|
|
|
await ChangeState(PlayButtonState.Idle);
|
2024-08-01 17:27:35 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 23:29:19 -05:00
|
|
|
if (primaryActions.Count() == 1)
|
|
|
|
|
{
|
2024-09-05 00:48:04 -05:00
|
|
|
var task = GameService.Run(game, primaryActions.First());
|
2024-06-10 23:29:19 -05:00
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
|
|
|
|
|
await task;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var modalOptions = new ModalOptions()
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
Title = LocalizationService.GetString("PlayGame", game.Title),
|
2024-06-10 23:29:19 -05:00
|
|
|
Maximizable = false,
|
|
|
|
|
DefaultMaximized = false,
|
|
|
|
|
Closable = true,
|
2025-01-27 21:07:38 -06:00
|
|
|
MaskClosable = true,
|
2024-06-10 23:29:19 -05:00
|
|
|
Footer = null,
|
|
|
|
|
Centered = true,
|
2024-09-05 00:48:04 -05:00
|
|
|
WrapClassName = "game-actions-dialog",
|
|
|
|
|
AfterClose = async () =>
|
|
|
|
|
{
|
|
|
|
|
Client.Lobbies.ReleaseSteam();
|
2025-01-27 21:07:38 -06:00
|
|
|
|
|
|
|
|
await ChangeState(PlayButtonState.Idle);
|
2024-09-05 00:48:04 -05:00
|
|
|
}
|
2024-06-10 23:29:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var model = new ActionSelectorDialogOptions
|
|
|
|
|
{
|
|
|
|
|
Actions = actions.Where(a => a.IsPrimaryAction),
|
2024-08-01 17:21:44 -05:00
|
|
|
Game = game
|
2024-06-10 23:29:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var modalRef = ModalService.CreateModal<ActionSelectorDialog, ActionSelectorDialogOptions, Process>(modalOptions, model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task Stop()
|
|
|
|
|
{
|
2025-01-12 21:49:30 -06:00
|
|
|
await ChangeState(PlayButtonState.Stopping);
|
|
|
|
|
|
2024-08-26 20:18:54 -05:00
|
|
|
await Client.Games.Stop(LibraryItem.Key);
|
2024-06-10 23:29:19 -05:00
|
|
|
|
2025-01-12 21:49:30 -06:00
|
|
|
await ChangeState(PlayButtonState.Idle);
|
2024-06-10 23:29:19 -05:00
|
|
|
}
|
|
|
|
|
|
2024-07-15 19:47:32 -05:00
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2024-08-26 20:18:54 -05:00
|
|
|
StateTimer.Dispose();
|
2024-07-15 19:47:32 -05:00
|
|
|
}
|
2024-06-10 23:29:19 -05:00
|
|
|
}
|