Skip to content

Commit

Permalink
Don't throw when user cancels UAC prompt during registry update (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz authored Oct 23, 2024
1 parent 68d131c commit 66a9b1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions LightBulb.PlatformInterop/RegistrySwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ public bool IsSet
{
// Run reg.exe with elevation
if (value)
{
Reg.SetValue(
hive.GetShortMoniker() + '\\' + keyName,
entryName,
enabledValue
);
}
else
{
Reg.DeleteValue(hive.GetShortMoniker() + '\\' + keyName, entryName);
}
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions LightBulb/Services/SettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text.Json.Serialization;
using Cogwheel;
Expand Down Expand Up @@ -278,8 +279,18 @@ public override void Save()
base.Save();

// Update values in the registry
_extendedGammaRangeSwitch.IsSet = IsExtendedGammaRangeUnlocked;
_autoStartSwitch.IsSet = IsAutoStartEnabled;
try
{
_extendedGammaRangeSwitch.IsSet = IsExtendedGammaRangeUnlocked;
_autoStartSwitch.IsSet = IsAutoStartEnabled;
}
catch (Win32Exception)
{
// This can happen if the user doesn't have the necessary permissions to update
// the corresponding registry keys, and privilege elevation has failed.
// Throwing an exception here is very messy, so we'll just ignore it.
// https://github.com/Tyrrrz/LightBulb/issues/335
}

// Trigger UI updates
OnPropertyChanged(string.Empty);
Expand Down

0 comments on commit 66a9b1d

Please sign in to comment.