private void CheckBoxBackgroundUpdater_Click(object sender, RoutedEventArgs e) { TaskSchHandler taskShedHandler = new TaskSchHandler(); if (CheckBoxBackgroundUpdater.IsChecked.Value) { taskShedHandler.CreateAppUpdaterTask(); Properties.Settings.Default.BackgroundUpdate = true; } else { taskShedHandler.RemoveAppUpdaterTask(); Properties.Settings.Default.BackgroundUpdate = false; } }
private void ApplyButton_Click(object sender, RoutedEventArgs e) { int darkStart; int darkStartMinutes; int lightStart; int lightStartMinutes; //get values from TextBox try { darkStart = int.Parse(darkStartBox.Text); darkStartMinutes = int.Parse(DarkStartMinutesBox.Text); lightStart = int.Parse(lightStartBox.Text); lightStartMinutes = int.Parse(LightStartMinutesBox.Text); } catch { userFeedback.Text = Properties.Resources.errorNumberInput; return; } //check values from TextBox if (!Properties.Settings.Default.AlterTime) { if (darkStart >= 24) { darkStart = 23; darkStartMinutes = 59; } if (lightStart >= darkStart) { lightStart = darkStart - 3; } if (lightStart < 0) { lightStart = 6; darkStart = 17; } } else { if (darkStart >= 12) { darkStart = 11; darkStartMinutes = 59; } if (lightStart >= 13) { lightStart = 12; } } if (lightStartMinutes > 59) { lightStartMinutes = 59; } if (darkStartMinutes > 59) { darkStartMinutes = 59; } darkStartBox.Text = Convert.ToString(darkStart); lightStartBox.Text = Convert.ToString(lightStart); if (lightStartMinutes < 10) { LightStartMinutesBox.Text = "0" + Convert.ToString(lightStartMinutes); } else { LightStartMinutesBox.Text = Convert.ToString(lightStartMinutes); } if (darkStartMinutes < 10) { DarkStartMinutesBox.Text = "0" + Convert.ToString(darkStartMinutes); } else { DarkStartMinutesBox.Text = Convert.ToString(darkStartMinutes); } try { if (Properties.Settings.Default.AlterTime) { darkStart += 12; } taskShedHandler.CreateTask(darkStart, darkStartMinutes, lightStart, lightStartMinutes); } catch (Exception ex) { userFeedback.Text = Properties.Resources.msgErrorOcc; string error = Properties.Resources.errorThemeApply + "\n\n Error ocurred in: taskShedHandler.CreateTask()" + "\n\n" + ex.Message; MsgBox msg = new MsgBox(error, Properties.Resources.errorOcurredTitle, "error", "yesno"); msg.ShowDialog(); var result = msg.DialogResult; if (result == true) { System.Diagnostics.Process.Start("https://github.com/Armin2208/Windows-Auto-Night-Mode/issues/44"); } return; } try { regEditHandler.SwitchThemeBasedOnTime(); } catch (Exception ex) { userFeedback.Text = Properties.Resources.msgErrorOcc; string error = Properties.Resources.errorThemeApply + "\n\n Error ocurred in: regEditHandler.SwitchThemeBasedOnTime()" + "\n\n" + ex.Message; MsgBox msg = new MsgBox(error, Properties.Resources.errorOcurredTitle, "error", "yesno"); msg.ShowDialog(); var result = msg.DialogResult; if (result == true) { System.Diagnostics.Process.Start("https://github.com/Armin2208/Windows-Auto-Night-Mode/issues/44"); } return; } try { regEditHandler.AddAutoStart(); } catch (Exception ex) { userFeedback.Text = Properties.Resources.msgErrorOcc; string error = Properties.Resources.errorThemeApply + "\n\n Error ocurred in: regEditHandler.AddAutoStart()" + "\n\n" + ex.Message; MsgBox msg = new MsgBox(error, Properties.Resources.errorOcurredTitle, "error", "yesno"); msg.ShowDialog(); var result = msg.DialogResult; if (result == true) { System.Diagnostics.Process.Start("https://github.com/Armin2208/Windows-Auto-Night-Mode/issues/44"); } return; } try { if (Properties.Settings.Default.BackgroundUpdate) { taskShedHandler.CreateAppUpdaterTask(); } } catch (Exception ex) { userFeedback.Text = Properties.Resources.msgErrorOcc; string error = Properties.Resources.errorThemeApply + "\n\n Error ocurred in: taskShedHandler.CreateAppUpdaterTask()" + "\n\n" + ex.Message; MsgBox msg = new MsgBox(error, Properties.Resources.errorOcurredTitle, "error", "yesno"); msg.ShowDialog(); var result = msg.DialogResult; if (result == true) { System.Diagnostics.Process.Start("https://github.com/Armin2208/Windows-Auto-Night-Mode/issues/44"); } return; } try { if (Properties.Settings.Default.connectedStandby) { taskShedHandler.CreateConnectedStandbyTask(); } } catch (Exception ex) { userFeedback.Text = Properties.Resources.msgErrorOcc; string error = Properties.Resources.errorThemeApply + "\n\n Error ocurred in: taskShedHandler.CreateConnectedStandbyTask()" + "\n\n" + ex.Message; MsgBox msg = new MsgBox(error, Properties.Resources.errorOcurredTitle, "error", "yesno"); msg.ShowDialog(); var result = msg.DialogResult; if (result == true) { System.Diagnostics.Process.Start("https://github.com/Armin2208/Windows-Auto-Night-Mode/issues/44"); } } applyButton.IsEnabled = false; if (PowerManager.EnergySaverStatus == EnergySaverStatus.On) { userFeedback.Text = Properties.Resources.msgChangesSaved + "\n\n" + Properties.Resources.msgBatterySaver; applyButton.IsEnabled = true; } else { userFeedback.Text = Properties.Resources.msgChangesSaved;//changes were saved! } }
private void ApplyTheme(int DarkHour, int DarkMinute, int LightHour, int LightMinute) { //create task scheduler theme switching tasks try { taskSchHandler.CreateTask(DarkHour, DarkMinute, LightHour, LightMinute); } catch (UnauthorizedAccessException ex) { MsgBox msg = new MsgBox(string.Format(Properties.Resources.ErrorApplyRestart, ex), Properties.Resources.errorOcurredTitle, "error", "close"); msg.Owner = Window.GetWindow(this); msg.ShowDialog(); //run AutoDarkMode.exe /removeTask as admin Process proc = new Process(); proc.StartInfo.FileName = Application.ResourceAssembly.Location; proc.StartInfo.Arguments = "/removeTask"; proc.StartInfo.UseShellExecute = true; proc.StartInfo.Verb = "runas"; proc.Start(); //restart app Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); return; } catch (Exception ex) { ErrorWhileApplyingTheme("Error ocurred in: taskShedHandler.CreateTask()", ex.Message); return; } //switch the theme now try { regEditHandler.SwitchThemeBasedOnTime(); } catch (Exception ex) { ErrorWhileApplyingTheme("Error ocurred in: regEditHandler.SwitchThemeBasedOnTime()", ex.Message); return; } //create windows autostart entry try { if (Settings.Default.LogonTaskInsteadOfAutostart) { taskSchHandler.CreateLogonTask(); } else { regEditHandler.AddAutoStart(); } } catch (Exception ex) { ErrorWhileApplyingTheme("Error ocurred in: taskShedHandler.AddAutoStart()", ex.Message); return; } //add background updater task try { if (Settings.Default.BackgroundUpdate) { taskSchHandler.CreateAppUpdaterTask(); } } catch (Exception ex) { ErrorWhileApplyingTheme("Error ocurred in: taskShedHandler.CreateAppUpdaterTask()", ex.Message); return; } //add connected standby task try { if (Properties.Settings.Default.connectedStandby) { taskSchHandler.CreateConnectedStandbyTask(); } } catch (Exception ex) { ErrorWhileApplyingTheme("Error ocurred in: taskShedHandler.CreateConnectedStandbyTask()", ex.Message); } //this setting enables all the configuration possibilities of auto dark mode Settings.Default.Enabled = true; //show warning for notebook on battery with enabled battery saver if (PowerManager.EnergySaverStatus == EnergySaverStatus.On) { userFeedback.Text = Properties.Resources.msgChangesSaved + "\n\n" + Properties.Resources.msgBatterySaver; applyButton.IsEnabled = true; } else { userFeedback.Text = Properties.Resources.msgChangesSaved;//changes were saved! } }