private void CheckBoxLogonTask_Click(object sender, RoutedEventArgs e) { RegeditHandler regeditHandler = new RegeditHandler(); TaskSchHandler taskScheduler = new TaskSchHandler(); if (CheckBoxLogonTask.IsChecked.Value) { regeditHandler.RemoveAutoStart(); taskScheduler.CreateLogonTask(); Settings.Default.LogonTaskInsteadOfAutostart = true; } else { taskScheduler.RemoveLogonTask(); regeditHandler.AddAutoStart(); Settings.Default.LogonTaskInsteadOfAutostart = false; } }
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! } }