mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Refresh the mouse only every 20s in background. When GHelper becomes visible, force refresh all devices.
This commit is contained in:
@@ -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<IPeripheral> l = AllPeripherals();
|
||||
|
||||
foreach (IPeripheral m in l)
|
||||
|
||||
@@ -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 == "")
|
||||
|
||||
Reference in New Issue
Block a user