Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bb26c1c3f | |||
| f8aa7c9118 |
@@ -17,7 +17,7 @@ internal static class Data
|
||||
|
||||
internal static ObservableCollection<SensorEntry> SensorEntries { get; set; } = [];
|
||||
|
||||
internal static async Task LoadComputer()
|
||||
private static async Task LoadComputer()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -30,8 +30,11 @@ internal static class Data
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RefreshComputer()
|
||||
internal static async Task RefreshComputer()
|
||||
{
|
||||
if (_pipeClient is not { State: PipeState.Connected })
|
||||
await LoadComputer();
|
||||
|
||||
_hardware = _pipeClient.InvokeAsync(service => service.GetHardware()).Result;
|
||||
}
|
||||
|
||||
|
||||
9
StatusWindow/Resources.Designer.cs
generated
9
StatusWindow/Resources.Designer.cs
generated
@@ -169,6 +169,15 @@ namespace HardwareMonitorStatusWindow.StatusWindow {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Current Value.
|
||||
/// </summary>
|
||||
public static string CurrentValueWatermark {
|
||||
get {
|
||||
return ResourceManager.GetString("CurrentValueWatermark", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Delete.
|
||||
/// </summary>
|
||||
|
||||
@@ -248,4 +248,7 @@ Would you like to download and install it now?</value>
|
||||
<data name="ServiceNotStarted" xml:space="preserve">
|
||||
<value>Waiting for service to start...</value>
|
||||
</data>
|
||||
<data name="CurrentValueWatermark" xml:space="preserve">
|
||||
<value>Current Value</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -67,13 +67,13 @@ public partial class HardwareSettingsPanel
|
||||
EditSelectedSensor();
|
||||
}
|
||||
|
||||
private void AddSensor()
|
||||
private async void AddSensor()
|
||||
{
|
||||
var sensorEntry = new SensorEntry();
|
||||
|
||||
var sensorWindow = new SensorWindow();
|
||||
|
||||
var result = sensorWindow.Display(sensorEntry, Window.GetWindow(this));
|
||||
var result = await sensorWindow.Display(sensorEntry, Window.GetWindow(this));
|
||||
|
||||
if (!result.HasValue || !result.Value)
|
||||
return;
|
||||
@@ -83,7 +83,7 @@ public partial class HardwareSettingsPanel
|
||||
SetSensorButtonStates();
|
||||
}
|
||||
|
||||
private void EditSelectedSensor()
|
||||
private async void EditSelectedSensor()
|
||||
{
|
||||
if (SensorDataGrid.SelectedItem == null)
|
||||
return;
|
||||
@@ -92,7 +92,7 @@ public partial class HardwareSettingsPanel
|
||||
|
||||
var sensorWindow = new SensorWindow();
|
||||
|
||||
sensorWindow.Display(sensorEntry, Window.GetWindow(this));
|
||||
await sensorWindow.Display(sensorEntry, Window.GetWindow(this));
|
||||
}
|
||||
|
||||
private void DeleteSelectedSensors()
|
||||
|
||||
@@ -68,8 +68,14 @@
|
||||
DisplayMemberPath="Name"
|
||||
VirtualizingPanel.IsVirtualizing="False"
|
||||
mah:TextBoxHelper.UseFloatingWatermark="True"
|
||||
mah:TextBoxHelper.Watermark="{x:Static hardwareMonitorStatusWindow:Resources.SensorWatermark}">
|
||||
mah:TextBoxHelper.Watermark="{x:Static hardwareMonitorStatusWindow:Resources.SensorWatermark}"
|
||||
SelectionChanged="SensorComboBox_SelectionChanged">
|
||||
</ComboBox>
|
||||
<TextBox Name="CurrentValueTextBox"
|
||||
mah:TextBoxHelper.UseFloatingWatermark="True"
|
||||
mah:TextBoxHelper.Watermark="{x:Static hardwareMonitorStatusWindow:Resources.CurrentValueWatermark}"
|
||||
mah:TextBoxHelper.SelectAllOnFocus="True"
|
||||
IsReadOnly="True" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="0"
|
||||
Grid.Row="1"
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System;
|
||||
using ChrisKaczor.Wpf.Validation;
|
||||
using HardwareMonitorStatusWindow.Service;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
|
||||
|
||||
public partial class SensorWindow
|
||||
{
|
||||
private readonly DispatcherTimer _timer = new();
|
||||
|
||||
public SensorWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public bool? Display(SensorEntry sensorEntry, Window? owner)
|
||||
public async Task<bool?> Display(SensorEntry sensorEntry, Window? owner)
|
||||
{
|
||||
DataContext = sensorEntry;
|
||||
|
||||
Data.RefreshComputer();
|
||||
await Data.RefreshComputer();
|
||||
|
||||
HardwareTypeComboBox.ItemsSource = Data.ComputerHardware.Where(h => h.Sensors.Any()).DistinctBy(h => h.Type).Select(s => new HardwareTypeItem(s.Type)).OrderBy(s => s.Name);
|
||||
|
||||
@@ -32,9 +38,18 @@ public partial class SensorWindow
|
||||
|
||||
Owner = owner;
|
||||
|
||||
_timer.Interval = TimeSpan.FromSeconds(1);
|
||||
_timer.Tick += TimerOnTick;
|
||||
_timer.Start();
|
||||
|
||||
return ShowDialog();
|
||||
}
|
||||
|
||||
private void TimerOnTick(object? sender, EventArgs e)
|
||||
{
|
||||
UpdateCurrentSensorValue();
|
||||
}
|
||||
|
||||
private void HandleOkayButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!this.IsValid())
|
||||
@@ -95,4 +110,26 @@ public partial class SensorWindow
|
||||
|
||||
SensorComboBox.ItemsSource = hardware.Sensors.Where(s => s.Type == sensorType.Value);
|
||||
}
|
||||
|
||||
private void SensorComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
||||
{
|
||||
UpdateCurrentSensorValue();
|
||||
}
|
||||
|
||||
private void UpdateCurrentSensorValue()
|
||||
{
|
||||
var sensor = (Sensor)SensorComboBox.SelectedItem;
|
||||
|
||||
if (sensor?.Value == null)
|
||||
{
|
||||
CurrentValueTextBox.Text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
var hardware = (Hardware)HardwareComboBox.SelectedItem;
|
||||
|
||||
var displaySensorEntry = new SensorEntry { HardwareId = hardware.Identifier, SensorId = sensor.Identifier };
|
||||
|
||||
CurrentValueTextBox.Text = string.Format(displaySensorEntry.SensorValueFormat, displaySensorEntry.Sensor!.Value);
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task Start(bool hasUpdate)
|
||||
private void Start(bool hasUpdate)
|
||||
{
|
||||
Log.Information("Start: hasUpdate={hasUpdate}", hasUpdate);
|
||||
|
||||
@@ -148,7 +148,7 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
|
||||
Log.Information("Load");
|
||||
|
||||
await Load();
|
||||
Load();
|
||||
|
||||
Log.Information("Starting timer");
|
||||
|
||||
@@ -157,10 +157,8 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
_timer.Enabled = true;
|
||||
}
|
||||
|
||||
private static async Task Load()
|
||||
private static void Load()
|
||||
{
|
||||
await Data.LoadComputer();
|
||||
|
||||
Data.Load();
|
||||
}
|
||||
|
||||
@@ -227,19 +225,24 @@ internal class WindowSource : IWindowSource, IDisposable
|
||||
if (existingTask == null)
|
||||
{
|
||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.ServiceNotInstalled));
|
||||
_timer.Start();
|
||||
return;
|
||||
}
|
||||
|
||||
if (existingTask.State != TaskState.Running)
|
||||
{
|
||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.ServiceNotStarted));
|
||||
|
||||
existingTask.Run();
|
||||
_timer.Start();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var text = new StringBuilder();
|
||||
|
||||
Data.RefreshComputer();
|
||||
Data.RefreshComputer().Wait();
|
||||
|
||||
foreach (var sensorEntry in Data.SensorEntries)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user