Improve startup
All checks were successful
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Successful in 48s

This commit is contained in:
2026-02-27 16:06:23 -05:00
parent f8aa7c9118
commit 5bb26c1c3f
4 changed files with 21 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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()

View File

@@ -2,6 +2,7 @@
using ChrisKaczor.Wpf.Validation;
using HardwareMonitorStatusWindow.Service;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Threading;
@@ -17,11 +18,11 @@ public partial class 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);

View File

@@ -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)
{