Skip to content

Commit 66fe636

Browse files
committed
UX: don't close UI or grey out commit button if admin rights were denied
1 parent 8ac2e4a commit 66fe636

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

GPUPrefSwitcher/OptionsFormUtils.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void ResetPreferencesXmlFile(bool showRestartConfirmation = true)
2424
}
2525
}
2626

27-
public static void AskRestartService()
27+
public static bool AskRestartService()
2828
{
2929

3030
const int ERROR_CANCELLED = 1223; //The operation was canceled by the user.
@@ -41,10 +41,15 @@ public static void AskRestartService()
4141
catch (Win32Exception ex)
4242
{
4343
if (ex.NativeErrorCode == ERROR_CANCELLED)
44+
{
4445
MessageBox.Show("Admin rights were denied, or error restarting service");
46+
return false;
47+
}
4548
else
4649
throw;
4750
}
51+
52+
return true;
4853
}
4954

5055
public static void AskDeleteFolders()

GPUPrefSwitcherGUI/MainForm.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,19 @@ private void RevertChangesButton_Click(object sender, EventArgs e)
423423

424424
private void CommitButton_Click(object sender, EventArgs e)
425425
{
426-
OptionsFormUtils.AskRestartService();
427-
CommitButton.Enabled = false;
426+
bool restartSuccess = OptionsFormUtils.AskRestartService();
428427

429-
/* //not sure this does anything because there's no gauruntee the serrice has updated the file; maybe we need some sort of file update listener?
428+
/* //not sure this does anything because there's no gauruntee the service has updated the file; maybe we need some sort of file update listener?
430429
switcherOptions.Reload();
431430
UpdateGrid();
432431
*/
433432

434-
Close();
433+
if (restartSuccess)
434+
{
435+
//CommitButton.Enabled = false;
436+
Close();
437+
}
438+
435439
}
436440

437441
private void OptionsButton_Click(object sender, EventArgs e)

GPUPrefSwitcherGUI/OptionsForm.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,19 @@ private void SpoofPowerStateComboBox_SelectedIndexChanged(object sender, EventAr
152152

153153
private void CommitChangesButton_Click(object sender, EventArgs e)
154154
{
155-
OptionsFormUtils.AskRestartService();
156-
CommitChangesButton.Enabled = false;
155+
bool restartSuccess = OptionsFormUtils.AskRestartService();
156+
157+
if(restartSuccess)
158+
{
159+
//CommitChangesButton.Enabled = false;
160+
parentMainForm.Close();
161+
}
157162

158163
/* //not sure this does anything because there's no gauruntee the serrice has updated the file; maybe we need some sort of file update listener?
159164
switcherOptions.Reload();
160165
UpdateFormComponents(switcherOptions.CurrentOptions);
161166
*/
162-
parentMainForm.Close();
167+
163168
}
164169

165170
private void SaveButton_Click_1(object sender, EventArgs e)

0 commit comments

Comments
 (0)