diff --git a/LenovoLegionToolkit.Lib/Controllers/RGBKeyboardBacklightController.cs b/LenovoLegionToolkit.Lib/Controllers/RGBKeyboardBacklightController.cs index 7049887920..f31a919486 100644 --- a/LenovoLegionToolkit.Lib/Controllers/RGBKeyboardBacklightController.cs +++ b/LenovoLegionToolkit.Lib/Controllers/RGBKeyboardBacklightController.cs @@ -55,7 +55,9 @@ public async Task SetLightControlOwnerAsync(bool enable, bool restorePreset = fa if (Log.Instance.IsTraceEnabled) Log.Instance.Trace($"Taking ownership..."); +#if !MOCK_RGB await WMI.WriteAsync("ROOT\\WMI", $"SELECT * FROM LENOVO_GAMEZONE_DATA", "SetLightControlOwner", new() { { "Data", enable ? 1 : 0 } }).ConfigureAwait(false); +#endif if (Log.Instance.IsTraceEnabled) Log.Instance.Trace($"Ownership set to {enable}, restoring profile..."); @@ -126,10 +128,16 @@ public async Task SetStateAsync(RGBKeyboardBacklightState state) public async Task SetPresetAsync(RGBKeyboardBacklightPreset preset) { - await ThrowIfVantageEnabled().ConfigureAwait(false); - using (await _ioLock.LockAsync().ConfigureAwait(false)) { +#if !MOCK_RGB + var handle = Devices.GetRGBKeyboard(); + if (handle is null) + throw new InvalidOperationException("RGB Keyboard unsupported."); +#endif + + await ThrowIfVantageEnabled().ConfigureAwait(false); + var state = _settings.Store.State; var presets = state.Presets; @@ -148,10 +156,16 @@ public async Task SetPresetAsync(RGBKeyboardBacklightPreset preset) public async Task SetNextPresetAsync() { - await ThrowIfVantageEnabled().ConfigureAwait(false); - using (await _ioLock.LockAsync().ConfigureAwait(false)) { +#if !MOCK_RGB + var handle = Devices.GetRGBKeyboard(); + if (handle is null) + throw new InvalidOperationException("RGB Keyboard unsupported."); +#endif + + await ThrowIfVantageEnabled().ConfigureAwait(false); + var state = _settings.Store.State; var newPreset = state.SelectedPreset.Next(); @@ -172,10 +186,16 @@ public async Task SetNextPresetAsync() private async Task SetCurrentPresetAsync() { - await ThrowIfVantageEnabled().ConfigureAwait(false); - using (await _ioLock.LockAsync().ConfigureAwait(false)) { +#if !MOCK_RGB + var handle = Devices.GetRGBKeyboard(); + if (handle is null) + throw new InvalidOperationException("RGB Keyboard unsupported."); +#endif + + await ThrowIfVantageEnabled().ConfigureAwait(false); + var state = _settings.Store.State; var preset = state.SelectedPreset;