Skip to content

Commit

Permalink
add Network Device selection to General Settings tab, for LocalPCInfo…
Browse files Browse the repository at this point in the history
…/NET properties
  • Loading branch information
Aytackydln committed Sep 15, 2024
1 parent 40beda9 commit 7f831b0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using LibreHardwareMonitor.Hardware;

Expand All @@ -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<IHardware> _networkDevices;
#endregion

public NetUpdater(IEnumerable<IHardware> 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");
Expand All @@ -31,5 +52,7 @@ public NetUpdater(IEnumerable<IHardware> hardware)
_uploadSpeed = FindSensor("throughput/7");
_downloadSpeed = FindSensor("throughput/8");
}

public IEnumerable<IHardware> GetNetworkDevices() => _networkDevices;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IHardwareMonitor : IDisposable
HardwareMonitor.CpuUpdater Cpu { get; }
HardwareMonitor.RamUpdater Ram { get; }
HardwareMonitor.NetUpdater Net { get; }

List<string> NetworkAdapters { get; }
}

public sealed class NoopHardwareMonitor : IHardwareMonitor
Expand All @@ -29,6 +31,9 @@ public sealed class NoopHardwareMonitor : IHardwareMonitor
public HardwareMonitor.RamUpdater Ram => _ram.Value;

public HardwareMonitor.NetUpdater Net => _net.Value;

public List<string> NetworkAdapters => [];

public void Dispose()
{
}
Expand All @@ -51,6 +56,8 @@ public sealed partial class HardwareMonitor: IHardwareMonitor
private static readonly Computer _computer;
public NetUpdater Net => _net.Value;

public List<string> 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
Expand Down
5 changes: 4 additions & 1 deletion Project-Aurora/Project-Aurora/Nodes/LocalPCInformation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AuroraRgb.Modules;
using System.Collections.Generic;
using AuroraRgb.Modules;
using AuroraRgb.Modules.HardwareMonitor;

namespace AuroraRgb.Nodes;
Expand Down Expand Up @@ -67,4 +68,6 @@ public class LocalPcInformation : Node

private DesktopNode? _desktop;
public DesktopNode Desktop => _desktop ??= new DesktopNode();

public static List<string> NetworkAdapters => HardwareMonitor.NetworkAdapters;
}
2 changes: 2 additions & 0 deletions Project-Aurora/Project-Aurora/Settings/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> Migrations { get; set; } = [];

public bool? AutoInstallGsi { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<UserControl.Resources>
Expand Down Expand Up @@ -158,21 +159,29 @@
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock Margin="0,1,0,1" Text="GSI Playback Device:" />
<ComboBox Grid.Row="0" Grid.Column="1" Margin="0,1,0,1" SelectedValue="{Binding Path=GsiAudioRenderDevice, Mode=TwoWay}"
ItemsSource="{x:Static audioCapture:AudioDevices.PlaybackDevices}" DisplayMemberPath="Value"
SelectedValuePath="Key" Width="185" />
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,1,0,1" Text="GSI Recording Device:" />

<ComboBox Grid.Row="1" Grid.Column="1" Margin="0,1,0,1" SelectedValue="{Binding Path=GsiAudioCaptureDevice, Mode=TwoWay}"
ItemsSource="{x:Static audioCapture:AudioDevices.RecordingDevices}" DisplayMemberPath="Value"
SelectedValuePath="Key" Width="185" />
<TextBlock Grid.Row="1" Grid.Column="2" Text="?" TextDecorations="Underline"
ToolTip="The audio recording device that will be used for the local PC information state values. Does not affect visualizer layer."
ToolTipService.InitialShowDelay="0" VerticalAlignment="Center" HorizontalAlignment="Center" />

<TextBlock Grid.Row="2" Grid.Column="0" Margin="0,1,0,1" Text="GSI Network Device:" />
<ComboBox Grid.Row="2" Grid.Column="1" Margin="0,1,0,1" SelectedValue="{Binding Path=GsiNetworkDevice, Mode=TwoWay}"
ItemsSource="{x:Static nodes:LocalPcInformation.NetworkAdapters}"
Width="185" />
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,1,0,1" Text="GSI Recording Device:" />
</Grid>

<!-- Location -->
<TextBlock Margin="0,1,0,1">Location:</TextBlock>
<Canvas Height="20">
Expand Down

0 comments on commit 7f831b0

Please sign in to comment.