LANCommander/LANCommander.Server/UI/Pages/Settings/Launcher.razor
Pat Hartl add770b227 Refactor Settings
Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
2025-11-16 12:31:25 -06:00

91 lines
3.1 KiB
Text

@page "/Settings/Launcher"
@using LANCommander.Server.Jobs.Background
@using LANCommander.Server.Settings
@using LANCommander.Server.Settings.Enums
@using Microsoft.Extensions.Options
@inject IMessageService MessageService
@inject ILogger<Updates> Logger
@inject IOptions<Settings> Settings
@inject SettingsProvider<Settings> SettingsProvider
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="Launcher">
<PageHeaderExtra>
<Button OnClick="DownloadLaunchers" Disabled="!Settings.Value.Server.Launcher.HostUpdates">Download Launchers</Button>
</PageHeaderExtra>
</PageHeader>
<PageContent>
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
<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" />
</FormItem>
<FormItem Label="Host Client Updates">
<Switch @bind-Checked="context.Server.Launcher.HostUpdates" />
</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>
<FormItem>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</FormItem>
</Form>
</PageContent>
@code {
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
void Save()
{
try
{
SettingsProvider.Update(s =>
{
s.Server.Launcher = Settings.Value.Server.Launcher;
});
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;
}
async Task DownloadLaunchers()
{
Hangfire.BackgroundJob.Enqueue<DownloadLauncherArtifacts>(x => x.ExecuteAsync());
MessageService.Success("Launchers will be downloaded in the background!");
}
}