Added a PowerModeChanged event handler to reset the hardware tree when resuming from sleep. This should correctly restore fan controls and other states.

This commit is contained in:
Michael Möller 2020-05-17 18:13:32 +02:00
parent 39cfbc709d
commit e82b9d7da2
3 changed files with 36 additions and 11 deletions

View File

@ -172,6 +172,8 @@ namespace OpenHardwareMonitor.GUI {
computer.Open(); computer.Open();
Microsoft.Win32.SystemEvents.PowerModeChanged += PowerModeChanged;
timer.Enabled = true; timer.Enabled = true;
showHiddenSensors = new UserOption("hiddenMenuItem", false, 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() { private void InitializePlotForm() {
plotForm = new Form(); plotForm = new Form();
plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow; plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
@ -880,8 +890,7 @@ namespace OpenHardwareMonitor.GUI {
// disable the fallback MainIcon during reset, otherwise icon visibility // disable the fallback MainIcon during reset, otherwise icon visibility
// might be lost // might be lost
systemTray.IsMainIconEnabled = false; systemTray.IsMainIconEnabled = false;
computer.Close(); computer.Reset();
computer.Open();
// restore the MainIcon setting // restore the MainIcon setting
systemTray.IsMainIconEnabled = minimizeToTray.Value; systemTray.IsMainIconEnabled = minimizeToTray.Value;
} }

View File

@ -84,9 +84,15 @@ namespace OpenHardwareMonitor.Hardware {
Ring0.Open(); Ring0.Open();
Opcode.Open(); Opcode.Open();
AddGroups();
open = true;
}
private void AddGroups() {
if (mainboardEnabled) if (mainboardEnabled)
Add(new Mainboard.MainboardGroup(smbios, settings)); Add(new Mainboard.MainboardGroup(smbios, settings));
if (cpuEnabled) if (cpuEnabled)
Add(new CPU.CPUGroup(settings)); Add(new CPU.CPUGroup(settings));
@ -105,8 +111,14 @@ namespace OpenHardwareMonitor.Hardware {
if (hddEnabled) if (hddEnabled)
Add(new HDD.HarddriveGroup(settings)); Add(new HDD.HarddriveGroup(settings));
}
open = true; public void Reset() {
if (!open)
return;
RemoveGroups();
AddGroups();
} }
public bool MainboardEnabled { public bool MainboardEnabled {
@ -347,14 +359,11 @@ namespace OpenHardwareMonitor.Hardware {
} }
} }
public void Close() { public void Close() {
if (!open) if (!open)
return; return;
while (groups.Count > 0) { RemoveGroups();
IGroup group = groups[groups.Count - 1];
Remove(group);
}
Opcode.Close(); Opcode.Close();
Ring0.Close(); Ring0.Close();
@ -364,6 +373,13 @@ namespace OpenHardwareMonitor.Hardware {
open = false; open = false;
} }
private void RemoveGroups() {
while (groups.Count > 0) {
IGroup group = groups[groups.Count - 1];
Remove(group);
}
}
public event HardwareEventHandler HardwareAdded; public event HardwareEventHandler HardwareAdded;
public event HardwareEventHandler HardwareRemoved; public event HardwareEventHandler HardwareRemoved;

View File

@ -10,5 +10,5 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("0.9.3.2")] [assembly: AssemblyVersion("0.9.3.3")]
[assembly: AssemblyInformationalVersion("0.9.3.2 Alpha")] [assembly: AssemblyInformationalVersion("0.9.3.3 Alpha")]