Fixed auto start functionality

DM wasn't autstarting when the checkbox on the MainForm was started. It wasn't correctly enabling the setting. It now does.
This commit is contained in:
Terry MacDonald 2021-10-31 16:22:21 +13:00
parent f72fc6feea
commit 2da00a55ec
3 changed files with 24 additions and 9 deletions

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information // Version information
[assembly: AssemblyVersion("2.1.0.71")] [assembly: AssemblyVersion("2.1.0.73")]
[assembly: AssemblyFileVersion("2.1.0.71")] [assembly: AssemblyFileVersion("2.1.0.73")]
[assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]

View File

@ -489,7 +489,7 @@ namespace DisplayMagician.UIForms
allowClose = false; allowClose = false;
// Enable the MinimiseOnStart setting // Enable the MinimiseOnStart setting
Program.AppProgramSettings.MinimiseOnStart = true; Program.AppProgramSettings.MinimiseOnStart = true;
Program.AppProgramSettings.StartOnBootUp = true; SettingsForm.SetBootMeUp(true);
// Change the exit_button text to say 'Close' // Change the exit_button text to say 'Close'
btn_exit.Text = "&Close"; btn_exit.Text = "&Close";
} }
@ -501,7 +501,7 @@ namespace DisplayMagician.UIForms
allowClose = true; allowClose = true;
// Disable the MinimiseOnStart setting // Disable the MinimiseOnStart setting
Program.AppProgramSettings.MinimiseOnStart = false; Program.AppProgramSettings.MinimiseOnStart = false;
Program.AppProgramSettings.StartOnBootUp = false; SettingsForm.SetBootMeUp(false);
// Change the exit_button text to say 'Exit' // Change the exit_button text to say 'Exit'
btn_exit.Text = "&Exit"; btn_exit.Text = "&Exit";

View File

@ -172,10 +172,8 @@ namespace DisplayMagician.UIForms
} }
private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e) public static bool SetBootMeUp(bool enabled)
{ {
logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings LogLevel set to Trace");
var bootMeUp = new BootMeUp var bootMeUp = new BootMeUp
{ {
UseAlternativeOnFail = true, UseAlternativeOnFail = true,
@ -184,7 +182,7 @@ namespace DisplayMagician.UIForms
}; };
// save start on Boot up // save start on Boot up
if (cb_start_on_boot.Checked) if (enabled)
{ {
Program.AppProgramSettings.StartOnBootUp = true; Program.AppProgramSettings.StartOnBootUp = true;
bootMeUp.Enabled = true; bootMeUp.Enabled = true;
@ -192,9 +190,14 @@ namespace DisplayMagician.UIForms
{ {
logger.Error($"SettingsForm/SettingsForm_FormClosing: Failed to set up DisplayMagician to start when Windows starts"); logger.Error($"SettingsForm/SettingsForm_FormClosing: Failed to set up DisplayMagician to start when Windows starts");
MessageBox.Show("There was an issue setting DisplayMagician to run when the computer starts. Please try launching DisplayMagician again as Admin to see if that helps."); MessageBox.Show("There was an issue setting DisplayMagician to run when the computer starts. Please try launching DisplayMagician again as Admin to see if that helps.");
return false;
} }
else else
{
logger.Info($"SettingsForm/SettingsForm_FormClosing: Successfully set DisplayMagician to start when Windows starts"); logger.Info($"SettingsForm/SettingsForm_FormClosing: Successfully set DisplayMagician to start when Windows starts");
return true;
}
} }
else else
{ {
@ -204,11 +207,23 @@ namespace DisplayMagician.UIForms
{ {
logger.Error($"SettingsForm/SettingsForm_FormClosing: Failed to stop DisplayMagician from starting when Windows starts"); logger.Error($"SettingsForm/SettingsForm_FormClosing: Failed to stop DisplayMagician from starting when Windows starts");
MessageBox.Show("There was an issue stopping DisplayMagician from running when the computer starts. Please try launching DisplayMagician again as Admin to see if that helps."); MessageBox.Show("There was an issue stopping DisplayMagician from running when the computer starts. Please try launching DisplayMagician again as Admin to see if that helps.");
return false;
} }
else else
{
logger.Info($"SettingsForm/SettingsForm_FormClosing: Successfully stopped DisplayMagician from starting when Windows starts"); logger.Info($"SettingsForm/SettingsForm_FormClosing: Successfully stopped DisplayMagician from starting when Windows starts");
return true;
} }
}
}
private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
{
logger.Info($"SettingsForm/SettingsForm_Load: Setting BootMeUp to {cb_start_on_boot.Checked}");
SetBootMeUp(cb_start_on_boot.Checked);
// save minimise on close // save minimise on close
if (cb_minimise_notification_area.Checked) if (cb_minimise_notification_area.Checked)
Program.AppProgramSettings.MinimiseOnStart = true; Program.AppProgramSettings.MinimiseOnStart = true;