Add PowerModeChanged event handler to reset the hardware tree when resuming from sleep
Based on the work of @moellerm
This commit is contained in:
@@ -123,7 +123,7 @@ namespace LibreHardwareMonitor.UI
|
||||
_systemTray.ExitCommand += ExitClick;
|
||||
|
||||
if (Software.OperatingSystem.IsUnix)
|
||||
{
|
||||
{
|
||||
// Unix
|
||||
treeView.RowHeight = Math.Max(treeView.RowHeight, 18);
|
||||
splitContainer.BorderStyle = BorderStyle.None;
|
||||
@@ -355,7 +355,9 @@ namespace LibreHardwareMonitor.UI
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Show();
|
||||
}
|
||||
|
||||
// Create a handle, otherwise calling Close() does not fire FormClosed
|
||||
|
||||
@@ -367,6 +369,17 @@ namespace LibreHardwareMonitor.UI
|
||||
if (_runWebServer.Value)
|
||||
Server.Quit();
|
||||
};
|
||||
|
||||
Microsoft.Win32.SystemEvents.PowerModeChanged += PowerModeChanged;
|
||||
}
|
||||
|
||||
private void PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs eventArgs)
|
||||
{
|
||||
|
||||
if (eventArgs.Mode == Microsoft.Win32.PowerModes.Resume)
|
||||
{
|
||||
_computer.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeSplitter()
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace LibreHardwareMonitor.Hardware
|
||||
{
|
||||
private readonly List<IGroup> _groups = new List<IGroup>();
|
||||
private readonly ISettings _settings;
|
||||
private bool _cpuEnabled;
|
||||
private bool _controllerEnabled;
|
||||
private bool _cpuEnabled;
|
||||
private bool _gpuEnabled;
|
||||
private bool _memoryEnabled;
|
||||
private bool _motherboardEnabled;
|
||||
@@ -359,6 +359,13 @@ namespace LibreHardwareMonitor.Hardware
|
||||
Ring0.Open();
|
||||
OpCode.Open();
|
||||
|
||||
AddGroups();
|
||||
|
||||
_open = true;
|
||||
}
|
||||
|
||||
private void AddGroups()
|
||||
{
|
||||
if (_motherboardEnabled)
|
||||
Add(new MotherboardGroup(_smbios, _settings));
|
||||
|
||||
@@ -387,8 +394,6 @@ namespace LibreHardwareMonitor.Hardware
|
||||
|
||||
if (_networkEnabled)
|
||||
Add(new NetworkGroup(_settings));
|
||||
|
||||
_open = true;
|
||||
}
|
||||
|
||||
private static void NewSection(TextWriter writer)
|
||||
@@ -481,6 +486,25 @@ namespace LibreHardwareMonitor.Hardware
|
||||
_open = false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (!_open)
|
||||
return;
|
||||
|
||||
|
||||
RemoveGroups();
|
||||
AddGroups();
|
||||
}
|
||||
|
||||
private void RemoveGroups()
|
||||
{
|
||||
while (_groups.Count > 0)
|
||||
{
|
||||
IGroup group = _groups[_groups.Count - 1];
|
||||
Remove(group);
|
||||
}
|
||||
}
|
||||
|
||||
private class Settings : ISettings
|
||||
{
|
||||
public bool Contains(string name)
|
||||
|
||||
Reference in New Issue
Block a user