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

55 lines
1.9 KiB
Text
Raw Permalink Normal View History

@page "/Settings/Beacon"
2025-04-25 00:59:13 -05:00
@using LANCommander.SDK
@inject Client Client
@inject IMessageService MessageService
2024-07-07 16:33:46 -05:00
@inject ILogger<Beacon> Logger
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="Beacon" />
2025-02-04 19:32:33 -06:00
<PageContent>
<Form Model="Settings" 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.Beacon.Enabled" />
</FormItem>
2024-08-26 21:29:25 -05:00
<FormItem Label="Name">
<Text Type="@TextElementType.Secondary">Use this to customize the name that is broadcasted to clients.</Text>
<Input @bind-Value="Settings.Beacon.Name" />
</FormItem>
<FormItem Label="Address">
<Text Type="@TextElementType.Secondary">Use this to customize the address that is broadcasted to clients. Default: http://&lt;Server IP&gt;:@context.Port</Text>
<Input @bind-Value="Settings.Beacon.Address" />
</FormItem>
<FormItem>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</FormItem>
</Form>
2025-02-04 19:32:33 -06:00
</PageContent>
@code {
Settings Settings = SettingService.GetSettings();
2025-04-25 00:59:13 -05:00
async Task Save()
{
try
{
SettingService.SaveSettings(Settings);
MessageService.Success("Settings saved!");
2025-04-25 00:59:13 -05:00
if (Settings.Beacon.Enabled)
await Client.Beacon.StartBeaconAsync(Settings.Beacon.Port, Settings.Beacon.Address, Settings.Beacon.Name);
else
await Client.Beacon.StopBeaconAsync();
}
2024-07-07 16:33:46 -05:00
catch (Exception ex)
{
MessageService.Error("An unknown error occurred.");
2024-07-07 16:33:46 -05:00
Logger.LogError(ex, "An unknown error occurred.");
}
}
}