Skip to content

Commit

Permalink
UX: don't close UI or grey out commit button if admin rights were denied
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpjd committed May 28, 2024
1 parent 8ac2e4a commit 66fe636
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 6 additions & 1 deletion GPUPrefSwitcher/OptionsFormUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void ResetPreferencesXmlFile(bool showRestartConfirmation = true)
}
}

public static void AskRestartService()
public static bool AskRestartService()
{

const int ERROR_CANCELLED = 1223; //The operation was canceled by the user.
Expand All @@ -41,10 +41,15 @@ public static void AskRestartService()
catch (Win32Exception ex)
{
if (ex.NativeErrorCode == ERROR_CANCELLED)
{
MessageBox.Show("Admin rights were denied, or error restarting service");
return false;
}
else
throw;
}

return true;
}

public static void AskDeleteFolders()
Expand Down
12 changes: 8 additions & 4 deletions GPUPrefSwitcherGUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,19 @@ private void RevertChangesButton_Click(object sender, EventArgs e)

private void CommitButton_Click(object sender, EventArgs e)
{
OptionsFormUtils.AskRestartService();
CommitButton.Enabled = false;
bool restartSuccess = OptionsFormUtils.AskRestartService();

/* //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?
/* //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?
switcherOptions.Reload();
UpdateGrid();
*/

Close();
if (restartSuccess)
{
//CommitButton.Enabled = false;
Close();
}

}

private void OptionsButton_Click(object sender, EventArgs e)
Expand Down
11 changes: 8 additions & 3 deletions GPUPrefSwitcherGUI/OptionsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,19 @@ private void SpoofPowerStateComboBox_SelectedIndexChanged(object sender, EventAr

private void CommitChangesButton_Click(object sender, EventArgs e)
{
OptionsFormUtils.AskRestartService();
CommitChangesButton.Enabled = false;
bool restartSuccess = OptionsFormUtils.AskRestartService();

if(restartSuccess)
{
//CommitChangesButton.Enabled = false;
parentMainForm.Close();
}

/* //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?
switcherOptions.Reload();
UpdateFormComponents(switcherOptions.CurrentOptions);
*/
parentMainForm.Close();

}

private void SaveButton_Click_1(object sender, EventArgs e)
Expand Down

0 comments on commit 66fe636

Please sign in to comment.