From 4f31502055e1b8581238b26ccdb567cb9986b1b1 Mon Sep 17 00:00:00 2001 From: Aytackydln Date: Thu, 31 Oct 2024 00:33:28 +0100 Subject: [PATCH] fix razer update lock not releasing at launch --- .../Nodes/Razer/RazerFetcher.cs | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/Project-Aurora/Project-Aurora/Nodes/Razer/RazerFetcher.cs b/Project-Aurora/Project-Aurora/Nodes/Razer/RazerFetcher.cs index bb28a280c..c6f5924c7 100644 --- a/Project-Aurora/Project-Aurora/Nodes/Razer/RazerFetcher.cs +++ b/Project-Aurora/Project-Aurora/Nodes/Razer/RazerFetcher.cs @@ -44,8 +44,9 @@ protected RazerFetcher() { try { - if (!_mutex.WaitOne(TimeSpan.FromMilliseconds(2000), true)) + if (!_mutex.WaitOne(TimeSpan.FromMilliseconds(2000), false)) { + _mutex.ReleaseMutex(); return null; } } @@ -54,23 +55,37 @@ protected RazerFetcher() //continue } - var usbDevice = GetUsbDevice(); - if (usbDevice == null) - { - _mutex.ReleaseMutex(); - return null; - } - - var productKeyString = GetDeviceProductKeyString(usbDevice); - var mouseHidInfo = OnlineConfiguration.RazerDeviceInfo.MouseHidInfos[productKeyString]; - var message = GetMessage(mouseHidInfo); - - var report = GetReport(usbDevice, message); + var report = UpdateLocked(); _mutex.ReleaseMutex(); return report; } + private byte[]? UpdateLocked() + { + try + { + var usbDevice = GetUsbDevice(); + if (usbDevice == null) + { + return null; + } + + var productKeyString = GetDeviceProductKeyString(usbDevice); + var mouseHidInfo = OnlineConfiguration.RazerDeviceInfo.MouseHidInfos[productKeyString]; + var message = GetMessage(mouseHidInfo); + + var report = GetReport(usbDevice, message); + + return report; + } + catch(Exception e) + { + Global.logger.Error(e, "Failed to update Razer device status"); + return null; + } + } + protected abstract byte[] GetMessage(RazerMouseHidInfo mouseHidInfo); private static UsbDevice? GetUsbDevice()