LANCommander/LANCommander.Server/UI/Pages/Settings/Launcher.razor

92 lines
3.1 KiB
Text
Raw Permalink Normal View History

2024-07-25 19:22:37 -05:00
@page "/Settings/Launcher"
@using LANCommander.Server.Jobs.Background
@using LANCommander.Server.Settings
@using LANCommander.Server.Settings.Enums
@using Microsoft.Extensions.Options
2024-07-25 19:22:37 -05:00
@inject IMessageService MessageService
@inject ILogger<Updates> Logger
@inject IOptions<Settings> Settings
@inject SettingsProvider<Settings> SettingsProvider
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
2024-07-25 19:22:37 -05:00
<PageHeader Title="Launcher">
<PageHeaderExtra>
<Button OnClick="DownloadLaunchers" Disabled="!Settings.Value.Server.Launcher.HostUpdates">Download Launchers</Button>
</PageHeaderExtra>
</PageHeader>
2024-07-25 19:22:37 -05:00
2025-02-04 19:32:33 -06:00
<PageContent>
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
2024-07-25 19:22:37 -05:00
<FormItem Label="Storage Path">
<FilePicker Root="@RootPath" EntrySelectable="x => x is FileManagerDirectory" @bind-Value="@context.Server.Launcher.StoragePath" OkText="Select Path" Title="Choose Path" OnSelected="OnPathSelected" />
2024-07-25 19:22:37 -05:00
</FormItem>
<FormItem Label="Host Client Updates">
<Switch @bind-Checked="context.Server.Launcher.HostUpdates" />
2024-07-25 19:22:37 -05:00
</FormItem>
<FormItem Label="Always include Online Updates">
<Switch @bind-Checked="context.Server.Launcher.IncludeOnlineUpdates" />
</FormItem>
<FormItem Label="Architectures">
<EnumSelect
TEnum="LauncherArchitecture"
Mode="SelectMode.Multiple"
Disabled="!context.Server.Launcher.HostUpdates"
@bind-Values="context.Server.Launcher.Architectures" />
</FormItem>
<FormItem Label="Platforms">
<EnumSelect
TEnum="LauncherPlatform"
Mode="SelectMode.Multiple"
Disabled="!context.Server.Launcher.HostUpdates"
@bind-Values="context.Server.Launcher.Platforms" />
</FormItem>
2024-07-25 19:22:37 -05:00
<FormItem>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</FormItem>
</Form>
2025-02-04 19:32:33 -06:00
</PageContent>
2024-07-25 19:22:37 -05:00
@code {
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
void Save()
{
try
{
SettingsProvider.Update(s =>
{
s.Server.Launcher = Settings.Value.Server.Launcher;
});
2024-07-25 19:22:37 -05:00
MessageService.Success("Settings saved!");
}
catch (Exception ex)
{
MessageService.Error("An unknown error occurred.");
Logger.LogError(ex, "An unknown error occurred.");
}
}
void OnPathSelected(string path)
{
var appPath = Directory.GetCurrentDirectory();
if (path != null && path.StartsWith(appPath))
path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
Settings.Value.Server.Launcher.StoragePath = path;
2024-07-25 19:22:37 -05:00
}
async Task DownloadLaunchers()
{
Hangfire.BackgroundJob.Enqueue<DownloadLauncherArtifacts>(x => x.ExecuteAsync());
MessageService.Success("Launchers will be downloaded in the background!");
}
2024-07-25 19:22:37 -05:00
}