Exemplo n.º 1
0
        public async Task SetLocationSilent()
        {
            TaskShedHandler taskShedHandler = new TaskShedHandler();

            int[] sundate = await CalculateSunTime(true);

            taskShedHandler.CreateTask(sundate[2], sundate[3], sundate[0], sundate[1]);
        }
Exemplo n.º 2
0
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            //get values from TextBox
            int darkStart         = int.Parse(darkStartBox.Text);
            int darkStartMinutes  = int.Parse(DarkStartMinutesBox.Text);
            int lightStart        = int.Parse(lightStartBox.Text);
            int lightStartMinutes = int.Parse(LightStartMinutesBox.Text);

            //check values from TextBox
            if (darkStart >= 24)
            {
                darkStart        = 23;
                darkStartMinutes = 59;
            }
            if (lightStart >= darkStart)
            {
                lightStart = darkStart - 3;
            }
            if (lightStart < 0)
            {
                lightStart = 1;
                darkStart  = 3;
            }
            if (lightStartMinutes > 59)
            {
                lightStartMinutes = 59;
            }
            if (darkStartMinutes > 59)
            {
                darkStartMinutes = 59;
            }

            darkStartBox.Text         = Convert.ToString(darkStart);
            lightStartBox.Text        = Convert.ToString(lightStart);
            LightStartMinutesBox.Text = Convert.ToString(lightStartMinutes);
            DarkStartMinutesBox.Text  = Convert.ToString(darkStartMinutes);

            try
            {
                taskShedHandler.CreateTask(darkStart, darkStartMinutes, lightStart, lightStartMinutes);
                RegEditHandler.SwitchThemeBasedOnTime();
                RegEditHandler.AddAutoStart();

                //UI
                userFeedback.Text     = Properties.Resources.msgChangesSaved;//changes were saved!
                applyButton.IsEnabled = false;
            }
            catch {
                userFeedback.Text = Properties.Resources.msgErrorOcc;//error occurred :(
            }
        }
Exemplo n.º 3
0
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            //get values from TextBox
            int darkStart  = int.Parse(darkStartBox.Text);
            int lightStart = int.Parse(lightStartBox.Text);

            //check values from TextBox
            if (darkStart > 24)
            {
                darkStart         = 24;
                darkStartBox.Text = Convert.ToString(darkStart);
            }
            if (lightStart >= darkStart)
            {
                lightStart         = darkStart - 1;
                lightStartBox.Text = Convert.ToString(lightStart);
            }
            if (lightStart < 0)
            {
                lightStart         = 23;
                lightStartBox.Text = Convert.ToString(lightStart);
            }

            try
            {
                taskShedHandler.CreateTask(darkStart, lightStart);

                //fit current theme to the time
                var time = DateTime.Now.Hour;
                if (time <= lightStart || time >= darkStart)
                {
                    RegEditHandler.ThemeToDark();
                }
                else if (time >= lightStart || time <= darkStart)
                {
                    RegEditHandler.ThemeToLight();
                }

                //UI
                userFeedback.Text = "changes were saved!";
            }
            catch {
                userFeedback.Text = "error occurred :(";
            }
        }
Exemplo n.º 4
0
        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);
            LightStartMinutesBox.Text = Convert.ToString(lightStartMinutes);
            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")
                {
                    Owner = GetWindow(this)
                };
                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")
                {
                    Owner = GetWindow(this)
                };
                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")
                {
                    Owner = GetWindow(this)
                };
                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")
                {
                    Owner = GetWindow(this)
                };
                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")
                {
                    Owner = GetWindow(this)
                };
                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!
            }
        }