Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw when user cancels UAC prompt during registry update #338

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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