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();
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;
}