Skip to content

Commit

Permalink
Made RGB more consistent in the way they throw errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszCichecki committed Jun 30, 2022
1 parent 8d7dc22 commit c0c3aca
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit c0c3aca

Please sign in to comment.