From e82b9d7da284b40ababa4daa7537fc930f1af53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Sun, 17 May 2020 18:13:32 +0200 Subject: [PATCH] Added a PowerModeChanged event handler to reset the hardware tree when resuming from sleep. This should correctly restore fan controls and other states. --- GUI/MainForm.cs | 13 +++++++++++-- Hardware/Computer.cs | 30 +++++++++++++++++++++++------- Properties/AssemblyVersion.cs | 4 ++-- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 217ff9b..905a809 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -172,6 +172,8 @@ namespace OpenHardwareMonitor.GUI { computer.Open(); + Microsoft.Win32.SystemEvents.PowerModeChanged += PowerModeChanged; + timer.Enabled = true; showHiddenSensors = new UserOption("hiddenMenuItem", false, @@ -334,6 +336,14 @@ namespace OpenHardwareMonitor.GUI { }; } + private void PowerModeChanged(object sender, + Microsoft.Win32.PowerModeChangedEventArgs e) { + + if (e.Mode == Microsoft.Win32.PowerModes.Resume) { + computer.Reset(); + } + } + private void InitializePlotForm() { plotForm = new Form(); plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow; @@ -880,8 +890,7 @@ namespace OpenHardwareMonitor.GUI { // disable the fallback MainIcon during reset, otherwise icon visibility // might be lost systemTray.IsMainIconEnabled = false; - computer.Close(); - computer.Open(); + computer.Reset(); // restore the MainIcon setting systemTray.IsMainIconEnabled = minimizeToTray.Value; } diff --git a/Hardware/Computer.cs b/Hardware/Computer.cs index 8a77c90..d5245bc 100644 --- a/Hardware/Computer.cs +++ b/Hardware/Computer.cs @@ -84,9 +84,15 @@ namespace OpenHardwareMonitor.Hardware { Ring0.Open(); Opcode.Open(); + AddGroups(); + + open = true; + } + + private void AddGroups() { if (mainboardEnabled) Add(new Mainboard.MainboardGroup(smbios, settings)); - + if (cpuEnabled) Add(new CPU.CPUGroup(settings)); @@ -105,8 +111,14 @@ namespace OpenHardwareMonitor.Hardware { if (hddEnabled) Add(new HDD.HarddriveGroup(settings)); + } - open = true; + public void Reset() { + if (!open) + return; + + RemoveGroups(); + AddGroups(); } public bool MainboardEnabled { @@ -347,14 +359,11 @@ namespace OpenHardwareMonitor.Hardware { } } - public void Close() { + public void Close() { if (!open) return; - while (groups.Count > 0) { - IGroup group = groups[groups.Count - 1]; - Remove(group); - } + RemoveGroups(); Opcode.Close(); Ring0.Close(); @@ -364,6 +373,13 @@ namespace OpenHardwareMonitor.Hardware { open = false; } + private void RemoveGroups() { + while (groups.Count > 0) { + IGroup group = groups[groups.Count - 1]; + Remove(group); + } + } + public event HardwareEventHandler HardwareAdded; public event HardwareEventHandler HardwareRemoved; diff --git a/Properties/AssemblyVersion.cs b/Properties/AssemblyVersion.cs index 8489e24..f05e622 100644 --- a/Properties/AssemblyVersion.cs +++ b/Properties/AssemblyVersion.cs @@ -10,5 +10,5 @@ using System.Reflection; -[assembly: AssemblyVersion("0.9.3.2")] -[assembly: AssemblyInformationalVersion("0.9.3.2 Alpha")] +[assembly: AssemblyVersion("0.9.3.3")] +[assembly: AssemblyInformationalVersion("0.9.3.3 Alpha")]