Skip to content

Commit e82b9d7

Browse files
committed
Added a PowerModeChanged event handler to reset the hardware tree when resuming from sleep. This should correctly restore fan controls and other states.
1 parent 39cfbc7 commit e82b9d7

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

GUI/MainForm.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public MainForm() {
172172

173173
computer.Open();
174174

175+
Microsoft.Win32.SystemEvents.PowerModeChanged += PowerModeChanged;
176+
175177
timer.Enabled = true;
176178

177179
showHiddenSensors = new UserOption("hiddenMenuItem", false,
@@ -334,6 +336,14 @@ public MainForm() {
334336
};
335337
}
336338

339+
private void PowerModeChanged(object sender,
340+
Microsoft.Win32.PowerModeChangedEventArgs e) {
341+
342+
if (e.Mode == Microsoft.Win32.PowerModes.Resume) {
343+
computer.Reset();
344+
}
345+
}
346+
337347
private void InitializePlotForm() {
338348
plotForm = new Form();
339349
plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
@@ -880,8 +890,7 @@ private void resetClick(object sender, EventArgs e) {
880890
// disable the fallback MainIcon during reset, otherwise icon visibility
881891
// might be lost
882892
systemTray.IsMainIconEnabled = false;
883-
computer.Close();
884-
computer.Open();
893+
computer.Reset();
885894
// restore the MainIcon setting
886895
systemTray.IsMainIconEnabled = minimizeToTray.Value;
887896
}

Hardware/Computer.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,15 @@ public void Open() {
8484
Ring0.Open();
8585
Opcode.Open();
8686

87+
AddGroups();
88+
89+
open = true;
90+
}
91+
92+
private void AddGroups() {
8793
if (mainboardEnabled)
8894
Add(new Mainboard.MainboardGroup(smbios, settings));
89-
95+
9096
if (cpuEnabled)
9197
Add(new CPU.CPUGroup(settings));
9298

@@ -105,8 +111,14 @@ public void Open() {
105111

106112
if (hddEnabled)
107113
Add(new HDD.HarddriveGroup(settings));
114+
}
108115

109-
open = true;
116+
public void Reset() {
117+
if (!open)
118+
return;
119+
120+
RemoveGroups();
121+
AddGroups();
110122
}
111123

112124
public bool MainboardEnabled {
@@ -347,14 +359,11 @@ public string GetReport() {
347359
}
348360
}
349361

350-
public void Close() {
362+
public void Close() {
351363
if (!open)
352364
return;
353365

354-
while (groups.Count > 0) {
355-
IGroup group = groups[groups.Count - 1];
356-
Remove(group);
357-
}
366+
RemoveGroups();
358367

359368
Opcode.Close();
360369
Ring0.Close();
@@ -364,6 +373,13 @@ public void Close() {
364373
open = false;
365374
}
366375

376+
private void RemoveGroups() {
377+
while (groups.Count > 0) {
378+
IGroup group = groups[groups.Count - 1];
379+
Remove(group);
380+
}
381+
}
382+
367383
public event HardwareEventHandler HardwareAdded;
368384
public event HardwareEventHandler HardwareRemoved;
369385

Properties/AssemblyVersion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ This Source Code Form is subject to the terms of the Mozilla Public
1010

1111
using System.Reflection;
1212

13-
[assembly: AssemblyVersion("0.9.3.2")]
14-
[assembly: AssemblyInformationalVersion("0.9.3.2 Alpha")]
13+
[assembly: AssemblyVersion("0.9.3.3")]
14+
[assembly: AssemblyInformationalVersion("0.9.3.3 Alpha")]

0 commit comments

Comments
 (0)