Files
HardwareMonitorStatusWindow/Service/HardwareMonitorService.cs
Chris Kaczor 89d750fbe6
All checks were successful
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Successful in 54s
Add some logging and handle update error
2026-01-27 20:30:48 -05:00

50 lines
1.3 KiB
C#

using LibreHardwareMonitor.Hardware;
using Serilog;
namespace HardwareMonitorStatusWindow.Service;
public class HardwareMonitorService : IHardwareMonitorService
{
public const string ScheduledTaskName = "HardwareMonitorService";
public const string PipeName = "HardwareMonitorService";
private static readonly Computer Computer;
private static readonly HardwareUpdateVisitor HardwareUpdateVisitor;
static HardwareMonitorService()
{
Log.Information("Creating computer");
Computer = new Computer
{
IsCpuEnabled = true,
IsGpuEnabled = true,
IsMemoryEnabled = true,
IsMotherboardEnabled = true,
IsControllerEnabled = true,
IsNetworkEnabled = true,
IsStorageEnabled = true,
IsBatteryEnabled = true,
IsPsuEnabled = true
};
Log.Information("Opening computer");
Computer.Open();
HardwareUpdateVisitor = new HardwareUpdateVisitor();
}
public IEnumerable<Hardware> GetHardware()
{
Log.Information("Updating computer");
Computer.Accept(HardwareUpdateVisitor);
Log.Information("Creating hardware entries");
var hardwareEntries = Computer.Hardware.Select(Hardware.Create);
return hardwareEntries;
}
}