diff --git a/app/Peripherals/PeripheralsProvider.cs b/app/Peripherals/PeripheralsProvider.cs index 23b91e16..73648207 100644 --- a/app/Peripherals/PeripheralsProvider.cs +++ b/app/Peripherals/PeripheralsProvider.cs @@ -12,6 +12,8 @@ namespace GHelper.Peripherals public static event EventHandler? DeviceChanged; + private static long lastRefresh; + public static bool IsMouseConnected() { lock (_LOCK) @@ -43,6 +45,15 @@ namespace GHelper.Peripherals public static void RefreshBatteryForAllDevices() { + RefreshBatteryForAllDevices(false); + } + + public static void RefreshBatteryForAllDevices(bool force) + { + //Polling the battery every 20s should be enough + if (!force && Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastRefresh) < 20_000) return; + lastRefresh = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + List l = AllPeripherals(); foreach (IPeripheral m in l) diff --git a/app/Settings.cs b/app/Settings.cs index bf05341c..9248ee7a 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -236,11 +236,16 @@ namespace GHelper { screenControl.InitScreen(); gpuControl.InitXGM(); - Task.Run((Action)PeripheralsProvider.RefreshBatteryForAllDevices); + Task.Run((Action)RefreshPeripheralsBattery); updateControl.CheckForUpdates(); } } + private void RefreshPeripheralsBattery() + { + PeripheralsProvider.RefreshBatteryForAllDevices(true); + } + private void ButtonUpdates_Click(object? sender, EventArgs e) { if (updates == null || updates.Text == "")