Mouse refreshes battery again during "ReadSensors". But it does that nonblocking and event driven.

This commit is contained in:
IceStormNG
2023-07-27 10:19:17 +02:00
parent 6e4b5226f5
commit a323bd85ab
2 changed files with 16 additions and 0 deletions

View File

@@ -63,6 +63,9 @@ namespace GHelper.Peripherals
{ {
lock (_LOCK) lock (_LOCK)
{ {
am.Disconnect -= Mouse_Disconnect;
am.MouseReadyChanged -= MouseReadyChanged;
am.BatteryUpdated -= BatteryUpdated;
ConnectedMice.Remove(am); ConnectedMice.Remove(am);
} }
if (DeviceChanged is not null) if (DeviceChanged is not null)
@@ -110,6 +113,8 @@ namespace GHelper.Peripherals
am.Disconnect += Mouse_Disconnect; am.Disconnect += Mouse_Disconnect;
am.MouseReadyChanged += MouseReadyChanged;
am.BatteryUpdated += BatteryUpdated;
if (DeviceChanged is not null) if (DeviceChanged is not null)
{ {
DeviceChanged(am, EventArgs.Empty); DeviceChanged(am, EventArgs.Empty);
@@ -117,6 +122,16 @@ namespace GHelper.Peripherals
UpdateSettingsView(); UpdateSettingsView();
} }
private static void BatteryUpdated(object? sender, EventArgs e)
{
UpdateSettingsView();
}
private static void MouseReadyChanged(object? sender, EventArgs e)
{
UpdateSettingsView();
}
private static void Mouse_Disconnect(object? sender, EventArgs e) private static void Mouse_Disconnect(object? sender, EventArgs e)
{ {
if (sender is null) if (sender is null)

View File

@@ -814,6 +814,7 @@ namespace GHelper
string battery = ""; string battery = "";
HardwareControl.ReadSensors(); HardwareControl.ReadSensors();
Task.Run((Action)PeripheralsProvider.RefreshBatteryForAllDevices);
if (HardwareControl.cpuTemp > 0) if (HardwareControl.cpuTemp > 0)
cpuTemp = ": " + Math.Round((decimal)HardwareControl.cpuTemp).ToString() + "°C"; cpuTemp = ": " + Math.Round((decimal)HardwareControl.cpuTemp).ToString() + "°C";