diff --git a/StatusWindow/SensorEntry.cs b/StatusWindow/SensorEntry.cs index 8a50eeb..d129157 100644 --- a/StatusWindow/SensorEntry.cs +++ b/StatusWindow/SensorEntry.cs @@ -1,11 +1,11 @@ -using System; +using HardwareMonitorStatusWindow.Service; +using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text.Json.Serialization; -using HardwareMonitorStatusWindow.Service; namespace HardwareMonitorStatusWindow.StatusWindow; @@ -18,7 +18,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged _dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged; } - public string? Label + public string Label { get; set @@ -28,7 +28,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged SetField(ref field, value); } - } + } = string.Empty; public string? HardwareId { @@ -51,7 +51,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged } [JsonIgnore] - public Hardware? Hardware => Data.ComputerHardware?.FirstOrDefault(h => h.Identifier.ToString() == HardwareId); + public Hardware? Hardware => Data.ComputerHardware.FirstOrDefault(h => h.Identifier.ToString() == HardwareId); [JsonIgnore] public Sensor? Sensor => Hardware?.Sensors.FirstOrDefault(s => s.Identifier.ToString() == SensorId); @@ -88,17 +88,16 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged public event PropertyChangedEventHandler? PropertyChanged; - protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) + private void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - protected bool SetField(ref T field, T value, [CallerMemberName] string? propertyName = null) + private void SetField(ref T field, T value, [CallerMemberName] string? propertyName = null) { - if (EqualityComparer.Default.Equals(field, value)) return false; + if (EqualityComparer.Default.Equals(field, value)) return; field = value; OnPropertyChanged(propertyName); - return true; } public string SensorValueFormat diff --git a/StatusWindow/StatusWindow.csproj b/StatusWindow/StatusWindow.csproj index 1ffdbe1..6006eca 100644 --- a/StatusWindow/StatusWindow.csproj +++ b/StatusWindow/StatusWindow.csproj @@ -28,7 +28,7 @@ - + diff --git a/StatusWindow/WindowSource.cs b/StatusWindow/WindowSource.cs index ce61cce..9de7e9c 100644 --- a/StatusWindow/WindowSource.cs +++ b/StatusWindow/WindowSource.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -244,6 +245,8 @@ internal class WindowSource : IWindowSource, IDisposable Data.RefreshComputer().Wait(); + var labelLength = Data.SensorEntries.Max(x => x.Label.Length); + foreach (var sensorEntry in Data.SensorEntries) { if (sensorEntry.Sensor == null) @@ -252,7 +255,7 @@ internal class WindowSource : IWindowSource, IDisposable if (text.Length > 0) text.AppendLine(); - text.Append($"{sensorEntry.Label}: {string.Format(sensorEntry.SensorValueFormat, sensorEntry.Sensor.Value)}"); + text.Append($"{sensorEntry.Label.PadLeft(labelLength)}: {string.Format(sensorEntry.SensorValueFormat, sensorEntry.Sensor.Value)}"); } _dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString()));