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 => { ... })
59 lines
2.2 KiB
Text
59 lines
2.2 KiB
Text
@page "/Settings/Beacon"
|
|
@using LANCommander.SDK.Services
|
|
@using LANCommander.Server.Settings
|
|
@using Microsoft.Extensions.Options
|
|
@inject BeaconClient BeaconClient
|
|
@inject IOptions<Settings> Settings
|
|
@inject SettingsProvider<Settings> SettingsProvider
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Beacon> Logger
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Beacon" />
|
|
|
|
<PageContent>
|
|
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="Enable">
|
|
<Text Type="@TextElementType.Secondary">Enabling the beacon will allow clients on the same network to auto-discover the LANCommander address.</Text>
|
|
<Switch @bind-Checked="context.Server.Beacon.Enabled" />
|
|
</FormItem>
|
|
|
|
<FormItem Label="Name">
|
|
<Text Type="@TextElementType.Secondary">Use this to customize the name that is broadcasted to clients.</Text>
|
|
<Input @bind-Value="context.Server.Beacon.Name" />
|
|
</FormItem>
|
|
|
|
<FormItem Label="Address">
|
|
<Text Type="@TextElementType.Secondary">Use this to customize the address that is broadcasted to clients. Default: http://<Server IP>:@context.Server.Beacon.Port</Text>
|
|
<Input @bind-Value="context.Server.Beacon.Address" />
|
|
</FormItem>
|
|
|
|
<FormItem>
|
|
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
|
|
</FormItem>
|
|
</Form>
|
|
</PageContent>
|
|
|
|
@code {
|
|
async Task Save()
|
|
{
|
|
try
|
|
{
|
|
SettingsProvider.Update(s =>
|
|
{
|
|
s.Server.Beacon = Settings.Value.Server.Beacon;
|
|
});
|
|
MessageService.Success("Settings saved!");
|
|
|
|
if (Settings.Value.Server.Beacon.Enabled)
|
|
await BeaconClient.StartBeaconAsync(Settings.Value.Server.Beacon.Port, Settings.Value.Server.Beacon.Address, Settings.Value.Server.Beacon.Name);
|
|
else
|
|
await BeaconClient.StopBeaconAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("An unknown error occurred.");
|
|
Logger.LogError(ex, "An unknown error occurred.");
|
|
}
|
|
}
|
|
}
|