From 8c61a7e3b5491fb005f8efbb6f83c181f5b4ae45 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Mon, 30 Oct 2023 18:45:11 -0500 Subject: [PATCH] Allow customization of the address that gets broadcast by the beacon --- .../Views/Authentication.xaml.cs | 5 +- LANCommander/Models/Settings.cs | 8 ++- LANCommander/Pages/Settings/Beacon.razor | 49 +++++++++++++++++++ LANCommander/Pages/Settings/General.razor | 6 --- .../Pages/Settings/SettingsLayout.razor | 1 + LANCommander/Program.cs | 2 +- LANCommander/Services/BeaconService.cs | 2 +- 7 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 LANCommander/Pages/Settings/Beacon.razor diff --git a/LANCommander.Playnite.Extension/Views/Authentication.xaml.cs b/LANCommander.Playnite.Extension/Views/Authentication.xaml.cs index 4155727..6b3db4f 100644 --- a/LANCommander.Playnite.Extension/Views/Authentication.xaml.cs +++ b/LANCommander.Playnite.Extension/Views/Authentication.xaml.cs @@ -40,7 +40,10 @@ namespace LANCommander.PlaynitePlugin.Views { var beacon = beacons.First(); - Context.ServerAddress = $"http://{beacon.Address.Address}:{beacon.Address.Port}"; + if (!String.IsNullOrWhiteSpace(beacon.Data) && Uri.TryCreate(beacon.Data, UriKind.Absolute, out var beaconUri)) + Context.ServerAddress = beaconUri.ToString(); + else + Context.ServerAddress = $"http://{beacon.Address.Address}:{beacon.Address.Port}"; this.ServerAddress.Text = Context.ServerAddress; diff --git a/LANCommander/Models/Settings.cs b/LANCommander/Models/Settings.cs index fc10f1c..a8f0aa9 100644 --- a/LANCommander/Models/Settings.cs +++ b/LANCommander/Models/Settings.cs @@ -9,18 +9,24 @@ public class LANCommanderSettings { public int Port { get; set; } = 1337; - public bool Beacon { get; set; } = true; public string DatabaseConnectionString { get; set; } = "Data Source=LANCommander.db;Cache=Shared"; public string IGDBClientId { get; set; } = ""; public string IGDBClientSecret { get; set; } = ""; public LANCommanderTheme Theme { get; set; } = LANCommanderTheme.Light; + public LANCommanderBeaconSettings Beacon { get; set; } = new LANCommanderBeaconSettings(); public LANCommanderAuthenticationSettings Authentication { get; set; } = new LANCommanderAuthenticationSettings(); public LANCommanderUserSaveSettings UserSaves { get; set; } = new LANCommanderUserSaveSettings(); public LANCommanderArchiveSettings Archives { get; set; } = new LANCommanderArchiveSettings(); public LANCommanderIPXRelaySettings IPXRelay { get; set; } = new LANCommanderIPXRelaySettings(); } + public class LANCommanderBeaconSettings + { + public bool Enabled { get; set; } = true; + public string Address { get; set; } = ""; + } + public class LANCommanderAuthenticationSettings { public bool RequireApproval { get; set; } = false; diff --git a/LANCommander/Pages/Settings/Beacon.razor b/LANCommander/Pages/Settings/Beacon.razor new file mode 100644 index 0000000..bdef90d --- /dev/null +++ b/LANCommander/Pages/Settings/Beacon.razor @@ -0,0 +1,49 @@ +@page "/Settings/Beacon" +@using LANCommander.Models; +@layout SettingsLayout +@inject SettingService SettingService +@inject IPXRelayService IPXRelayService +@inject IMessageService MessageService +@attribute [Authorize(Roles = "Administrator")] + + + +
+
+ + Enabling the beacon will allow clients on the same network to auto-discover the LANCommander address. + + + + + Use this to customize the address that is broadcasted to clients. Default: http://<Server IP>:@context.Port + + + + + + +
+
+ +@code { + LANCommanderSettings Settings; + + protected override async Task OnInitializedAsync() + { + Settings = SettingService.GetSettings(); + } + + private void Save() + { + try + { + SettingService.SaveSettings(Settings); + MessageService.Success("Settings saved!"); + } + catch + { + MessageService.Error("An unknown error occurred."); + } + } +} diff --git a/LANCommander/Pages/Settings/General.razor b/LANCommander/Pages/Settings/General.razor index 480e5fb..1b51e76 100644 --- a/LANCommander/Pages/Settings/General.razor +++ b/LANCommander/Pages/Settings/General.razor @@ -12,12 +12,6 @@
- - - - - Enabling the beacon will allow clients on the same network to auto-discover the LANCommander address. -