From 7f831b0899bb24ea7629d350a7fcbd15e30e753c Mon Sep 17 00:00:00 2001 From: Aytackydln Date: Mon, 16 Sep 2024 00:01:06 +0200 Subject: [PATCH] add Network Device selection to General Settings tab, for LocalPCInfo/NET properties --- .../HardwareMonitor.NETUpdater.cs | 31 ++++++++++++++++--- .../HardwareMonitor/HardwareMonitor.cs | 7 +++++ .../Nodes/LocalPCInformation.cs | 5 ++- .../Project-Aurora/Settings/Configuration.cs | 2 ++ .../Controls/Control_SettingsGeneral.xaml | 13 ++++++-- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Project-Aurora/Project-Aurora/Modules/HardwareMonitor/HardwareMonitor.NETUpdater.cs b/Project-Aurora/Project-Aurora/Modules/HardwareMonitor/HardwareMonitor.NETUpdater.cs index e226e5c57..c94106991 100644 --- a/Project-Aurora/Project-Aurora/Modules/HardwareMonitor/HardwareMonitor.NETUpdater.cs +++ b/Project-Aurora/Project-Aurora/Modules/HardwareMonitor/HardwareMonitor.NETUpdater.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using LibreHardwareMonitor.Hardware; @@ -9,19 +10,39 @@ public partial class HardwareMonitor public sealed class NetUpdater : HardwareUpdater { #region Sensors - private readonly ISensor? _bandwidthUsed; + private ISensor? _bandwidthUsed; public float BandwidthUsed => GetValue(_bandwidthUsed); - private readonly ISensor? _uploadSpeed; + private ISensor? _uploadSpeed; public float UploadSpeedBytes => GetValue(_uploadSpeed); - private readonly ISensor? _downloadSpeed; + private ISensor? _downloadSpeed; public float DownloadSpeedBytes => GetValue(_downloadSpeed); + + private readonly List _networkDevices; #endregion public NetUpdater(IEnumerable hardware) { - hw = hardware.FirstOrDefault(w => w.HardwareType == HardwareType.Network); + _networkDevices = hardware.Where(w => w.HardwareType == HardwareType.Network) + .ToList(); + + UpdateHardware(); + Global.Configuration.PropertyChanged += ConfigurationOnPropertyChanged; + + void ConfigurationOnPropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName != nameof(Global.Configuration.GsiNetworkDevice)) + { + return; + } + UpdateHardware(); + } + } + + private void UpdateHardware() + { + hw = _networkDevices.FirstOrDefault(w => w.Name == Global.Configuration.GsiNetworkDevice); if (hw is null) { Global.logger.Error("[HardwareMonitor] Could not find hardware of type Network or hardware monitoring is disabled"); @@ -31,5 +52,7 @@ public NetUpdater(IEnumerable hardware) _uploadSpeed = FindSensor("throughput/7"); _downloadSpeed = FindSensor("throughput/8"); } + + public IEnumerable GetNetworkDevices() => _networkDevices; } } \ No newline at end of file diff --git a/Project-Aurora/Project-Aurora/Modules/HardwareMonitor/HardwareMonitor.cs b/Project-Aurora/Project-Aurora/Modules/HardwareMonitor/HardwareMonitor.cs index dca8e0bcd..578c96065 100644 --- a/Project-Aurora/Project-Aurora/Modules/HardwareMonitor/HardwareMonitor.cs +++ b/Project-Aurora/Project-Aurora/Modules/HardwareMonitor/HardwareMonitor.cs @@ -13,6 +13,8 @@ public interface IHardwareMonitor : IDisposable HardwareMonitor.CpuUpdater Cpu { get; } HardwareMonitor.RamUpdater Ram { get; } HardwareMonitor.NetUpdater Net { get; } + + List NetworkAdapters { get; } } public sealed class NoopHardwareMonitor : IHardwareMonitor @@ -29,6 +31,9 @@ public sealed class NoopHardwareMonitor : IHardwareMonitor public HardwareMonitor.RamUpdater Ram => _ram.Value; public HardwareMonitor.NetUpdater Net => _net.Value; + + public List NetworkAdapters => []; + public void Dispose() { } @@ -51,6 +56,8 @@ public sealed partial class HardwareMonitor: IHardwareMonitor private static readonly Computer _computer; public NetUpdater Net => _net.Value; + public List NetworkAdapters => Net.GetNetworkDevices().Select(n => n.Name).ToList(); + #pragma warning disable CA1810 // Initialize reference type static fields inline static HardwareMonitor() #pragma warning restore CA1810 // Initialize reference type static fields inline diff --git a/Project-Aurora/Project-Aurora/Nodes/LocalPCInformation.cs b/Project-Aurora/Project-Aurora/Nodes/LocalPCInformation.cs index 9310954f1..38069dd50 100644 --- a/Project-Aurora/Project-Aurora/Nodes/LocalPCInformation.cs +++ b/Project-Aurora/Project-Aurora/Nodes/LocalPCInformation.cs @@ -1,4 +1,5 @@ -using AuroraRgb.Modules; +using System.Collections.Generic; +using AuroraRgb.Modules; using AuroraRgb.Modules.HardwareMonitor; namespace AuroraRgb.Nodes; @@ -67,4 +68,6 @@ public class LocalPcInformation : Node private DesktopNode? _desktop; public DesktopNode Desktop => _desktop ??= new DesktopNode(); + + public static List NetworkAdapters => HardwareMonitor.NetworkAdapters; } \ No newline at end of file diff --git a/Project-Aurora/Project-Aurora/Settings/Configuration.cs b/Project-Aurora/Project-Aurora/Settings/Configuration.cs index 77e9dd0d1..9bb5d5015 100644 --- a/Project-Aurora/Project-Aurora/Settings/Configuration.cs +++ b/Project-Aurora/Project-Aurora/Settings/Configuration.cs @@ -202,6 +202,8 @@ public class Configuration : INotifyPropertyChanged, IAuroraConfig [JsonProperty("GSIAudioCaptureDevice", NullValueHandling = NullValueHandling.Ignore)] public string GsiAudioCaptureDevice { get; set; } = AudioDevices.DefaultDeviceId; + public string GsiNetworkDevice { get; set; } = "Local Area Connection"; + public IList Migrations { get; set; } = []; public bool? AutoInstallGsi { get; set; } diff --git a/Project-Aurora/Project-Aurora/Settings/Controls/Control_SettingsGeneral.xaml b/Project-Aurora/Project-Aurora/Settings/Controls/Control_SettingsGeneral.xaml index 6a1495cc0..afadd5a1f 100644 --- a/Project-Aurora/Project-Aurora/Settings/Controls/Control_SettingsGeneral.xaml +++ b/Project-Aurora/Project-Aurora/Settings/Controls/Control_SettingsGeneral.xaml @@ -8,6 +8,7 @@ xmlns:auroraRgb="clr-namespace:AuroraRgb" xmlns:settings="clr-namespace:AuroraRgb.Settings" xmlns:audioCapture="clr-namespace:AuroraRgb.Modules.AudioCapture" + xmlns:nodes="clr-namespace:AuroraRgb.Nodes" Loaded="Control_SettingsGeneral_OnLoaded" mc:Ignorable="d"> @@ -158,21 +159,29 @@ + - + + + + + + - + Location: