Example #1
0
        private void imageListView1_SelectionChanged(object sender, EventArgs e)
        {
            if (imageListView1.SelectedItems.Count > 0)
            {
                selectedIndex = imageListView1.SelectedItems[0].Index;
                int imageNumber = 1;

                if (selectedIndex > 0)
                {
                    string themeId = (string)imageListView1.Items[selectedIndex].Tag;
                    selectedIndex = ThemeManager.themeSettings.FindIndex(
                        t => t.themeId == themeId) + 1;

                    SolarData   solarData = SunriseSunsetService.GetSolarData(DateTime.Today);
                    ThemeConfig theme     = ThemeManager.themeSettings[selectedIndex - 1];
                    imageNumber = GetImageList(theme).IndexOf(
                        AppContext.wpEngine.GetImageData(solarData, theme).Item1) + 1;
                }

                creditsLabel.Text = GetCreditsText();
                maxImageNumber    = GetMaxImageNumber();
                LoadPreviewImage(imageNumber);

                applyButton.Enabled = true;
            }
            else
            {
                applyButton.Enabled = false;
            }
        }
Example #2
0
        private SolarData GetSolarData(DateTime date)
        {
            SolarData data = SunriseSunsetService.GetSolarData(
                JsonConfig.settings.latitude, JsonConfig.settings.longitude, date);

            return(data);
        }
Example #3
0
        public void RunScheduler(bool forceImageUpdate = false)
        {
            if (!LaunchSequence.IsLocationReady() || !LaunchSequence.IsThemeReady())
            {
                return;
            }

            schedulerTimer.Stop();

            SolarData data = SunriseSunsetService.GetSolarData(DateTime.Today);

            isSunUp = (data.sunriseTime <= DateTime.Now && DateTime.Now < data.sunsetTime);
            DateTime?nextImageUpdateTime = null;

            if (ThemeManager.currentTheme != null)
            {
                if (forceImageUpdate)
                {
                    lastImagePath = null;
                }

                WallpaperShuffler.MaybeShuffleWallpaper();
                SchedulerState imageData = GetImageData(data, ThemeManager.currentTheme);
                SetWallpaper(imageData.imageId);
                nextImageUpdateTime = new DateTime(imageData.nextUpdateTicks);
            }

            SystemThemeChanger.TryUpdateSystemTheme();

            if (data.polarPeriod != PolarPeriod.None)
            {
                nextUpdateTime = DateTime.Today.AddDays(1);
            }
            else if (isSunUp)
            {
                nextUpdateTime = data.sunsetTime;
            }
            else if (DateTime.Now < data.solarTimes[0])
            {
                nextUpdateTime = data.sunriseTime;
            }
            else
            {
                SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                    DateTime.Today.AddDays(1));
                nextUpdateTime = tomorrowsData.sunriseTime;
            }

            if (nextImageUpdateTime.HasValue && nextImageUpdateTime.Value < nextUpdateTime.Value)
            {
                nextUpdateTime = nextImageUpdateTime;
            }

            StartTimer(nextUpdateTime.Value);
        }
        private async void okButton_Click(object sender, EventArgs e)
        {
            okButton.Enabled = false;

            if (!locationCheckBox.Checked)
            {
                LocationIQData data = LocationIQService.GetLocationData(inputBox.Text);

                if (data != null)
                {
                    JsonConfig.settings.location  = inputBox.Text;
                    JsonConfig.settings.latitude  = data.lat;
                    JsonConfig.settings.longitude = data.lon;
                    SolarData solarData = SunriseSunsetService.GetSolarData(DateTime.Today);

                    DialogResult result = MessageBox.Show(string.Format(_("Is this location " +
                                                                          "correct?\n\n{0}\nSunrise: {1}, Sunset: {2}"), data.display_name,
                                                                        solarData.sunriseTime.ToShortTimeString(),
                                                                        solarData.sunsetTime.ToShortTimeString()), _("Question"),
                                                          MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (result == DialogResult.Yes)
                    {
                        AppContext.wpEngine.RunScheduler();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show(_("The location you entered was invalid, or you are not " +
                                      "connected to the Internet. Check your Internet connection and try a " +
                                      "different location. You can use a complete address or just the name of " +
                                      "your city/region."), _("Error"), MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
            else
            {
                bool locationUpdated = await UwpLocation.UpdateGeoposition();

                if (locationUpdated)
                {
                    AppContext.wpEngine.RunScheduler();
                    this.Close();
                }
                else
                {
                    MessageBox.Show(_("Failed to get location from Windows location service."),
                                    _("Error"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            okButton.Enabled = true;
        }
Example #5
0
        public void RunScheduler(bool forceImageUpdate = false)
        {
            if (!LaunchSequence.IsLocationReady() || !ThemeManager.filesVerified)
            {
                return;
            }

            schedulerTimer.Stop();

            SolarData data = SunriseSunsetService.GetSolarData(DateTime.Today);

            isSunUp = (data.sunriseTime <= DateTime.Now && DateTime.Now < data.sunsetTime);
            DateTime?nextImageUpdateTime = null;

            if (ThemeManager.currentTheme != null)
            {
                if (forceImageUpdate)
                {
                    lastImagePath = null;
                }

                Tuple <int, long> imageData = GetImageData(data, ThemeManager.currentTheme,
                                                           JsonConfig.settings.darkMode);
                SetWallpaper(imageData.Item1);
                nextImageUpdateTime = new DateTime(imageData.Item2);
            }

            SystemThemeChanger.TryUpdateSystemTheme();

            if (isSunUp)
            {
                nextUpdateTime = data.sunsetTime;
            }
            else if (DateTime.Now < data.solarTimes[0])
            {
                nextUpdateTime = data.sunriseTime;
            }
            else
            {
                SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                    DateTime.Today.AddDays(1));
                nextUpdateTime = tomorrowsData.sunriseTime;
            }

            if (nextImageUpdateTime.HasValue && nextImageUpdateTime.Value < nextUpdateTime.Value)
            {
                nextUpdateTime = nextImageUpdateTime;
            }

            StartTimer(nextUpdateTime.Value);
        }
        public static string GeneratePreviewHtml(ThemeConfig theme)
        {
            string htmlText = Properties.Resources.preview_html;
            Dictionary <string, string> replacers = new Dictionary <string, string>();

            replacers.Add("basePath", new Uri(Environment.CurrentDirectory).AbsoluteUri);

            if (theme != null)
            {
                replacers.Add("themeName", ThemeManager.GetThemeName(theme));
                replacers.Add("themeAuthor", ThemeManager.GetThemeAuthor(theme));
                replacers.Add("previewMessage", string.Format(_("Previewing {0}"), "<span id=\"previewText\"></span>"));

                SolarData      solarData = SunriseSunsetService.GetSolarData(DateTime.Today);
                SchedulerState wpState   = AppContext.wpEngine.GetImageData(solarData, theme);

                if (ThemeManager.IsThemeDownloaded(theme))
                {
                    // TODO Why are images flickering?
                    ThemeImageData imageData   = GetThemeImageData(theme);
                    int            activeImage = imageData.FindIndex(entry => entry.Item2 == wpState.daySegment4) +
                                                 wpState.imageNumber;

                    replacers.Add("downloadMessage", "");
                    replacers.Add("carouselIndicators", GetCarouselIndicators(imageData.Count, activeImage));
                    replacers.Add("carouselItems", GetCarouselItems(imageData, activeImage, theme));
                }
                else
                {
                    replacers.Add("downloadMessage", string.Format("<div id=\"bottomCenterPanel\">{0}</div>",
                                                                   _("Theme is not downloaded. Click Download button to enable full preview.")));
                    replacers.Add("carouselIndicators", "");
                    replacers.Add("carouselItems", GetCarouselItems(wpState, theme));
                }
            }
            else
            {
                replacers.Add("themeAuthor", "Microsoft");

                int    startCarouselIndex = htmlText.IndexOf("<!--");
                int    endCarouselIndex   = htmlText.LastIndexOf("-->") + 3;
                string imageTag           = string.Format("<img src=\"{0}\">",
                                                          (new Uri(ThemeThumbLoader.GetWindowsWallpaper())).AbsoluteUri);

                htmlText = htmlText.Substring(0, startCarouselIndex) + imageTag +
                           htmlText.Substring(endCarouselIndex + 1);
            }

            return(RenderTemplate(htmlText, replacers));
        }
        private static void HandleLocationSuccess(LocationIQData data, ScheduleDialog dialog)
        {
            JsonConfig.settings.latitude  = data.lat;
            JsonConfig.settings.longitude = data.lon;
            SolarData solarData = SunriseSunsetService.GetSolarData(DateTime.Today);

            DialogResult result = MessageDialog.ShowQuestion(string.Format(_("Is this location correct?\n\n{0}\n{1}"),
                                                                           data.display_name, SunriseSunsetService.GetSunriseSunsetString(solarData)), _("Question"), true);

            if (result == DialogResult.Yes)
            {
                dialog.Invoke(new Action(() => dialog.HandleScheduleChange()));
            }
        }
Example #8
0
        private void UpdateSelectedItem()
        {
            if (imageListView1.SelectedItems.Count > 0)
            {
                selectedIndex = imageListView1.SelectedItems[0].Index;
                int  imageNumber     = 1;
                bool themeDownloaded = true;

                if (selectedIndex > 0)
                {
                    string themeId = (string)imageListView1.Items[selectedIndex].Tag;
                    selectedIndex = ThemeManager.themeSettings.FindIndex(
                        t => t.themeId == themeId) + 1;
                    ThemeConfig theme = ThemeManager.themeSettings[selectedIndex - 1];
                    themeDownloaded = ThemeManager.IsThemeDownloaded(theme);

                    if (themeDownloaded)
                    {
                        SolarData solarData = SunriseSunsetService.GetSolarData(DateTime.Today);
                        imageNumber = ThemeManager.GetThemeImageList(theme).IndexOf(
                            AppContext.wpEngine.GetImageData(solarData, theme).Item1) + 1;
                    }
                    else
                    {
                        LoadPreviewImage((Image)Properties.Resources.ResourceManager.GetObject(
                                             themeId + "_thumbnail"));
                    }
                }

                SetThemeDownloaded(themeDownloaded);
                creditsLabel.Text = GetCreditsText(themeDownloaded);

                if (themeDownloaded)
                {
                    maxImageNumber = GetMaxImageNumber();
                    LoadPreviewImage(imageNumber);
                }

                applyButton.Enabled = true;
            }
            else
            {
                applyButton.Enabled = false;
            }
        }
        private void UpdateSelectedItem()
        {
            if (imageListView1.SelectedItems.Count > 0)
            {
                selectedIndex = imageListView1.SelectedItems[0].Index;
                int  imageNumber     = 1;
                bool themeDownloaded = true;

                if (selectedIndex > 0)
                {
                    string themeId = (string)imageListView1.Items[selectedIndex].Tag;
                    selectedIndex = ThemeManager.themeSettings.FindIndex(t => t.themeId == themeId) + 1;
                    ThemeConfig theme = ThemeManager.themeSettings[selectedIndex - 1];
                    nameLabel.Text  = ThemeManager.GetThemeName(theme);
                    themeDownloaded = ThemeManager.IsThemeDownloaded(theme);

                    if (themeDownloaded)
                    {
                        SolarData solarData = SunriseSunsetService.GetSolarData(DateTime.Today);
                        imageNumber = ThemeManager.GetThemeImageList(theme).IndexOf(
                            AppContext.wpEngine.GetImageData(solarData, theme).imageId) + 1;
                        LoadPreviewImage(imageNumber);
                    }
                    else
                    {
                        LoadPreviewImage((Image)Properties.Resources.ResourceManager.GetObject(themeId + "_thumbnail"));
                    }
                }
                else
                {
                    nameLabel.Text = _("Windows Default");
                    LoadPreviewImage(new Bitmap(windowsWallpaper));
                }

                creditsLabel.Text        = GetCreditsText();
                downloadLabel.Visible    = selectedIndex > 0 && !themeDownloaded;
                previewLinkLabel.Visible = selectedIndex > 0 && themeDownloaded;
                applyButton.Enabled      = true;
            }
            else
            {
                applyButton.Enabled = false;
            }
        }
Example #10
0
        public void RunScheduler()
        {
            wallpaperTimer.Stop();

            DateTime today = DateTime.Today;

            todaysData = SunriseSunsetService.GetSolarData(today);

            if (DateTime.Now < todaysData.SunriseTime + timerError)
            {
                // Before sunrise
                yesterdaysData = SunriseSunsetService.GetSolarData(today.AddDays(-1));
                tomorrowsData  = null;
            }
            else if (DateTime.Now >= todaysData.SunsetTime - timerError)
            {
                // After sunset
                yesterdaysData = null;
                tomorrowsData  = SunriseSunsetService.GetSolarData(today.AddDays(1));
            }
            else
            {
                // Between sunrise and sunset
                yesterdaysData = null;
                tomorrowsData  = null;
            }

            isDayNow    = (yesterdaysData == null && tomorrowsData == null);
            lastImageId = -1;

            if (isDayNow)
            {
                UpdateDayImage();
            }
            else
            {
                UpdateNightImage();
            }

            SystemThemeChanger.TryUpdateSystemTheme();
            JsonConfig.SaveConfig();
        }
Example #11
0
        private DateTime UpdateImage(SolarData data, DaySegment segment)
        {
            int[]    imageList;
            DateTime segmentStart;
            DateTime segmentEnd;

            if (!JsonConfig.settings.darkMode)
            {
                switch (segment)
                {
                case DaySegment.Sunrise:
                    imageList    = ThemeManager.currentTheme.sunriseImageList;
                    segmentStart = data.solarTimes[0];
                    segmentEnd   = data.solarTimes[1];
                    break;

                case DaySegment.Day:
                    imageList    = ThemeManager.currentTheme.dayImageList;
                    segmentStart = data.solarTimes[1];
                    segmentEnd   = data.solarTimes[2];
                    break;

                case DaySegment.Sunset:
                    imageList    = ThemeManager.currentTheme.sunsetImageList;
                    segmentStart = data.solarTimes[2];
                    segmentEnd   = data.solarTimes[3];
                    break;

                default:
                    imageList = ThemeManager.currentTheme.nightImageList;

                    if (DateTime.Now < data.solarTimes[0])
                    {
                        SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(-1));
                        segmentStart = yesterdaysData.solarTimes[3];
                        segmentEnd   = data.solarTimes[0];
                    }
                    else
                    {
                        segmentStart = data.solarTimes[3];
                        SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(1));
                        segmentEnd = tomorrowsData.solarTimes[0];
                    }

                    break;
                }
            }
            else
            {
                imageList = ThemeManager.currentTheme.nightImageList;

                if (isSunUp)
                {
                    segmentStart = data.sunriseTime;
                    segmentEnd   = data.sunsetTime;
                }
                else if (DateTime.Now < data.sunriseTime)
                {
                    SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(-1));
                    segmentStart = yesterdaysData.sunsetTime;
                    segmentEnd   = data.sunriseTime;
                }
                else
                {
                    segmentStart = data.sunsetTime;
                    SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(1));
                    segmentEnd = tomorrowsData.sunriseTime;
                }
            }

            TimeSpan segmentLength = segmentEnd - segmentStart;
            TimeSpan timerLength   = new TimeSpan(segmentLength.Ticks / imageList.Length);

            int  imageNumber     = GetImageNumber(segmentStart, timerLength);
            long nextUpdateTicks = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1);

            SetWallpaper(imageList[imageNumber]);

            return(new DateTime(nextUpdateTicks));
        }
Example #12
0
        public void RunScheduler(bool forceImageUpdate = false)
        {
            if (!LaunchSequence.IsLocationReady() || !LaunchSequence.IsThemeReady())
            {
                return;
            }

            schedulerTimer.Stop();

            SolarData data = SunriseSunsetService.GetSolarData(DateTime.Today);

            isSunUp = (data.sunriseTime <= DateTime.Now && DateTime.Now < data.sunsetTime);
            DateTime?nextImageUpdateTime = null;

            //for (int i = 0; i < DisplayDevices.GetAllMonitorsFriendlyNames().Count(); i++)
            if (ThemeManager.currentTheme != null)
            {
                if (forceImageUpdate)
                {
                    lastImagePath = null;
                }

                ThemeShuffler.MaybeShuffleWallpaper();
            }

            SchedulerState imageData = GetImageData(data, ThemeManager.currentTheme, DateTime.Now);

            if (ThemeManager.currentTheme != null)
            {
                SetWallpaper(imageData.imageId);
                nextImageUpdateTime = new DateTime(imageData.nextUpdateTicks);
            }

            ScriptManager.RunScripts(new ScriptArgs
            {
                daySegment2 = imageData.daySegment2,
                daySegment4 = imageData.daySegment4,
                imagePath   = (ThemeManager.currentTheme != null) ? lastImagePath : null
            });

            if (data.polarPeriod != PolarPeriod.None)
            {
                nextUpdateTime = DateTime.Today.AddDays(1);
            }
            else if (isSunUp)
            {
                nextUpdateTime = data.sunsetTime;
            }
            else if (DateTime.Now < data.solarTimes[0])
            {
                nextUpdateTime = data.sunriseTime;
            }
            else
            {
                SolarData tomorrowsData = SunriseSunsetService.GetSolarData(DateTime.Today.AddDays(1));
                nextUpdateTime = tomorrowsData.sunriseTime;
            }

            if (nextImageUpdateTime.HasValue && nextImageUpdateTime.Value < nextUpdateTime.Value)
            {
                nextUpdateTime = nextImageUpdateTime;
            }

            StartTimer(nextUpdateTime.Value);
        }
Example #13
0
        public SchedulerState GetImageData(SolarData data, ThemeConfig theme, DateTime dateNow)
        {
            int[]          imageList = null;
            DateTime       segmentStart;
            DateTime       segmentEnd;
            SchedulerState imageData = new SchedulerState()
            {
                daySegment2 = isSunUp ? 0 : 1
            };

            // Use 4-segment mode if theme is not downloaded, or has sunrise/sunset images and dark mode not enabled
            if (theme?.imageFilename == null || (ThemeManager.IsTheme4Segment(theme) && !JsonConfig.settings.darkMode))
            {
                switch (GetDaySegment(data, dateNow))
                {
                case DaySegment.AlwaysDay:
                    imageList             = theme?.dayImageList;
                    segmentStart          = dateNow.Date;
                    segmentEnd            = dateNow.Date.AddDays(1);
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.AlwaysNight:
                    imageList             = theme?.nightImageList;
                    segmentStart          = dateNow.Date;
                    segmentEnd            = dateNow.Date.AddDays(1);
                    imageData.daySegment4 = 3;
                    break;

                case DaySegment.Sunrise:
                    imageList             = theme?.sunriseImageList;
                    segmentStart          = data.solarTimes[0];
                    segmentEnd            = data.solarTimes[1];
                    imageData.daySegment4 = 0;
                    break;

                case DaySegment.Day:
                    imageList             = theme?.dayImageList;
                    segmentStart          = data.solarTimes[1];
                    segmentEnd            = data.solarTimes[2];
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.Sunset:
                    imageList             = theme?.sunsetImageList;
                    segmentStart          = data.solarTimes[2];
                    segmentEnd            = data.solarTimes[3];
                    imageData.daySegment4 = 2;
                    break;

                default:
                    imageList             = theme?.nightImageList;
                    imageData.daySegment4 = 3;

                    if (dateNow < data.solarTimes[0])
                    {
                        SolarData yesterdaysData = SunriseSunsetService.GetSolarData(dateNow.Date.AddDays(-1));
                        segmentStart = yesterdaysData.solarTimes[3];
                        segmentEnd   = data.solarTimes[0];
                    }
                    else
                    {
                        segmentStart = data.solarTimes[3];
                        SolarData tomorrowsData = SunriseSunsetService.GetSolarData(dateNow.Date.AddDays(1));
                        segmentEnd = tomorrowsData.solarTimes[0];
                    }

                    break;
                }
            }
            else
            {
                imageList = theme?.nightImageList;

                if (!JsonConfig.settings.darkMode && (isSunUp || data.polarPeriod == PolarPeriod.PolarDay))
                {
                    imageList = theme?.dayImageList;
                }

                if (data.polarPeriod != PolarPeriod.None)
                {
                    segmentStart = dateNow.Date;
                    segmentEnd   = dateNow.Date.AddDays(1);
                }
                else if (isSunUp)
                {
                    segmentStart = data.sunriseTime;
                    segmentEnd   = data.sunsetTime;
                }
                else if (dateNow < data.sunriseTime)
                {
                    SolarData yesterdaysData = SunriseSunsetService.GetSolarData(dateNow.Date.AddDays(-1));
                    segmentStart = yesterdaysData.sunsetTime;
                    segmentEnd   = data.sunriseTime;
                }
                else
                {
                    segmentStart = data.sunsetTime;
                    SolarData tomorrowsData = SunriseSunsetService.GetSolarData(dateNow.Date.AddDays(1));
                    segmentEnd = tomorrowsData.sunriseTime;
                }
            }

            if (imageList != null)
            {
                TimeSpan segmentLength = segmentEnd - segmentStart;
                TimeSpan timerLength   = new TimeSpan(segmentLength.Ticks / imageList.Length);

                int imageNumber = (int)((dateNow.Ticks - segmentStart.Ticks) / timerLength.Ticks);
                imageData.imageId         = imageList[imageNumber];
                imageData.imageNumber     = imageNumber;
                imageData.nextUpdateTicks = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1);
            }

            return(imageData);
        }
Example #14
0
        public SchedulerState GetImageData(SolarData data, ThemeConfig theme)
        {
            int[]          imageList;
            DateTime       segmentStart;
            DateTime       segmentEnd;
            SchedulerState imageData = new SchedulerState()
            {
                daySegment2 = isSunUp ? 0 : 1
            };

            if (!JsonConfig.settings.darkMode)
            {
                switch (GetCurrentDaySegment(data))
                {
                case DaySegment.AllDay:
                    imageList    = theme.dayImageList;
                    segmentStart = DateTime.Today;
                    segmentEnd   = DateTime.Today.AddDays(1);
                    BrightnessManager.ChangeBrightness(0);
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.AllNight:
                    imageList    = theme.nightImageList;
                    segmentStart = DateTime.Today;
                    segmentEnd   = DateTime.Today.AddDays(1);
                    BrightnessManager.ChangeBrightness(1);
                    imageData.daySegment4 = 3;
                    break;

                case DaySegment.Sunrise:
                    imageList    = theme.sunriseImageList;
                    segmentStart = data.solarTimes[0];
                    segmentEnd   = data.solarTimes[1];
                    BrightnessManager.ChangeBrightness(2);
                    imageData.daySegment4 = 0;
                    break;

                case DaySegment.Day:
                    imageList    = theme.dayImageList;
                    segmentStart = data.solarTimes[1];
                    segmentEnd   = data.solarTimes[2];
                    BrightnessManager.ChangeBrightness(3);
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.Sunset:
                    imageList    = theme.sunsetImageList;
                    segmentStart = data.solarTimes[2];
                    segmentEnd   = data.solarTimes[3];
                    BrightnessManager.ChangeBrightness(4);
                    imageData.daySegment4 = 2;
                    break;

                default:
                    imageList             = theme.nightImageList;
                    imageData.daySegment4 = 3;

                    if (DateTime.Now < data.solarTimes[0])
                    {
                        SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(-1));
                        segmentStart = yesterdaysData.solarTimes[3];
                        segmentEnd   = data.solarTimes[0];
                    }
                    else
                    {
                        segmentStart = data.solarTimes[3];
                        SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(1));
                        segmentEnd = tomorrowsData.solarTimes[0];
                    }

                    BrightnessManager.ChangeBrightness(5);
                    break;
                }
            }
            else
            {
                imageList = theme.nightImageList;

                BrightnessManager.ChangeBrightness(5);

                if (data.polarPeriod != PolarPeriod.None)
                {
                    segmentStart = DateTime.Today;
                    segmentEnd   = DateTime.Today.AddDays(1);
                }
                else if (isSunUp)
                {
                    segmentStart = data.sunriseTime;
                    segmentEnd   = data.sunsetTime;
                }
                else if (DateTime.Now < data.sunriseTime)
                {
                    SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(-1));
                    segmentStart = yesterdaysData.sunsetTime;
                    segmentEnd   = data.sunriseTime;
                }
                else
                {
                    segmentStart = data.sunsetTime;
                    SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(1));
                    segmentEnd = tomorrowsData.sunriseTime;
                }
            }

            TimeSpan segmentLength = segmentEnd - segmentStart;
            TimeSpan timerLength   = new TimeSpan(segmentLength.Ticks / imageList.Length);

            int imageNumber = (int)((DateTime.Now - segmentStart).Ticks / timerLength.Ticks);

            imageData.imageId         = imageList[imageNumber];
            imageData.nextUpdateTicks = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1);

            return(imageData);
        }
        public SchedulerState GetImageData(SolarData data, ThemeConfig theme, DateTime current)
        {
            int[]    imageList = null;
            DateTime segmentStart;
            DateTime segmentEnd;
            bool     isSunUp = IsSunUp(data, current);

            SchedulerState imageData = new SchedulerState()
            {
                daySegment2 = isSunUp ? 0 : 1
            };

            if (!JsonConfig.settings.darkMode)
            {
                switch (GetDaySegment(data, current))
                {
                case DaySegment.AllDay:
                    imageList             = theme?.dayImageList;
                    segmentStart          = current.Date;
                    segmentEnd            = current.Date.AddDays(1);
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.AllNight:
                    imageList             = theme?.nightImageList;
                    segmentStart          = current.Date;
                    segmentEnd            = current.Date.AddDays(1);
                    imageData.daySegment4 = 3;
                    break;

                case DaySegment.Sunrise:
                    imageList             = theme?.sunriseImageList;
                    segmentStart          = data.solarTimes[0];
                    segmentEnd            = data.solarTimes[1];
                    imageData.daySegment4 = 0;
                    break;

                case DaySegment.Day:
                    imageList             = theme?.dayImageList;
                    segmentStart          = data.solarTimes[1];
                    segmentEnd            = data.solarTimes[2];
                    imageData.daySegment4 = 1;
                    break;

                case DaySegment.Sunset:
                    imageList             = theme?.sunsetImageList;
                    segmentStart          = data.solarTimes[2];
                    segmentEnd            = data.solarTimes[3];
                    imageData.daySegment4 = 2;
                    break;

                default:
                    imageList             = theme?.nightImageList;
                    imageData.daySegment4 = 3;

                    if (current < data.solarTimes[0])
                    {
                        SolarData yesterdaysData = SunriseSunsetService.GetSolarData(current.Date.AddDays(-1));
                        segmentStart = yesterdaysData.solarTimes[3];
                        segmentEnd   = data.solarTimes[0];
                    }
                    else
                    {
                        segmentStart = data.solarTimes[3];
                        SolarData tomorrowsData = SunriseSunsetService.GetSolarData(current.Date.AddDays(1));
                        segmentEnd = tomorrowsData.solarTimes[0];
                    }

                    break;
                }
            }
            else
            {
                imageList = theme?.nightImageList;

                if (data.polarPeriod != PolarPeriod.None)
                {
                    segmentStart = current.Date;
                    segmentEnd   = current.Date.AddDays(1);
                }
                else if (isSunUp)
                {
                    segmentStart = data.sunriseTime;
                    segmentEnd   = data.sunsetTime;
                }
                else if (current < data.sunriseTime)
                {
                    SolarData yesterdaysData = SunriseSunsetService.GetSolarData(current.Date.AddDays(-1));
                    segmentStart = yesterdaysData.sunsetTime;
                    segmentEnd   = data.sunriseTime;
                }
                else
                {
                    segmentStart = data.sunsetTime;
                    SolarData tomorrowsData = SunriseSunsetService.GetSolarData(current.Date.AddDays(1));
                    segmentEnd = tomorrowsData.sunriseTime;
                }
            }

            if (imageList != null)
            {
                TimeSpan segmentLength = segmentEnd - segmentStart;
                TimeSpan timerLength   = new TimeSpan(segmentLength.Ticks / imageList.Length);

                int imageNumber = (int)((current.Ticks - segmentStart.Ticks) / timerLength.Ticks);
                imageData.imageId     = imageList[imageNumber];
                imageData.imageNumber = imageNumber;
                imageData.startTick   = segmentStart.Ticks + timerLength.Ticks * imageNumber;
                imageData.endTick     = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1);
            }

            return(imageData);
        }
Example #16
0
        public Tuple <int, long> GetImageData(SolarData data, ThemeConfig theme)
        {
            int[]    imageList;
            DateTime segmentStart;
            DateTime segmentEnd;

            if (!JsonConfig.settings.darkMode)
            {
                switch (GetCurrentDaySegment(data))
                {
                case DaySegment.AllDay:
                    imageList    = theme.dayImageList;
                    segmentStart = DateTime.Today;
                    segmentEnd   = DateTime.Today.AddDays(1);
                    break;

                case DaySegment.AllNight:
                    imageList    = theme.nightImageList;
                    segmentStart = DateTime.Today;
                    segmentEnd   = DateTime.Today.AddDays(1);
                    break;

                case DaySegment.Sunrise:
                    imageList    = theme.sunriseImageList;
                    segmentStart = data.solarTimes[0];
                    segmentEnd   = data.solarTimes[1];
                    break;

                case DaySegment.Day:
                    imageList    = theme.dayImageList;
                    segmentStart = data.solarTimes[1];
                    segmentEnd   = data.solarTimes[2];
                    break;

                case DaySegment.Sunset:
                    imageList    = theme.sunsetImageList;
                    segmentStart = data.solarTimes[2];
                    segmentEnd   = data.solarTimes[3];
                    break;

                default:
                    imageList = theme.nightImageList;

                    if (DateTime.Now < data.solarTimes[0])
                    {
                        SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(-1));
                        segmentStart = yesterdaysData.solarTimes[3];
                        segmentEnd   = data.solarTimes[0];
                    }
                    else
                    {
                        segmentStart = data.solarTimes[3];
                        SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                            DateTime.Today.AddDays(1));
                        segmentEnd = tomorrowsData.solarTimes[0];
                    }

                    break;
                }
            }
            else
            {
                imageList = theme.nightImageList;

                if (data.polarPeriod != PolarPeriod.None)
                {
                    segmentStart = DateTime.Today;
                    segmentEnd   = DateTime.Today.AddDays(1);
                }
                else if (isSunUp)
                {
                    segmentStart = data.sunriseTime;
                    segmentEnd   = data.sunsetTime;
                }
                else if (DateTime.Now < data.sunriseTime)
                {
                    SolarData yesterdaysData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(-1));
                    segmentStart = yesterdaysData.sunsetTime;
                    segmentEnd   = data.sunriseTime;
                }
                else
                {
                    segmentStart = data.sunsetTime;
                    SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                        DateTime.Today.AddDays(1));
                    segmentEnd = tomorrowsData.sunriseTime;
                }
            }

            TimeSpan segmentLength = segmentEnd - segmentStart;
            TimeSpan timerLength   = new TimeSpan(segmentLength.Ticks / imageList.Length);

            int  imageNumber     = (int)((DateTime.Now - segmentStart).Ticks / timerLength.Ticks);
            long nextUpdateTicks = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1);

            return(new Tuple <int, long>(imageList[imageNumber], nextUpdateTicks));
        }
        public void RunScheduler(bool forceImageUpdate = false)
        {
            if (!LaunchSequence.IsLocationReady() || !LaunchSequence.IsThemeReady())
            {
                return;
            }

            schedulerTimer.Stop();

            SolarData data                = SunriseSunsetService.GetSolarData(DateTime.Today);
            bool      isSunUp             = IsSunUp(data, DateTime.Now);
            DateTime? nextImageUpdateTime = null;

            if (ThemeManager.currentTheme != null)
            {
                if (forceImageUpdate)
                {
                    lastImagePath = null;
                }

                WallpaperShuffler.MaybeShuffleWallpaper();
            }

            SchedulerState imageData = GetImageData(data, ThemeManager.currentTheme, DateTime.Now);

            if (ThemeManager.currentTheme != null)
            {
                nextImageUpdateTime = new DateTime(imageData.endTick);

                if (JsonConfig.settings.enableInterpolation)
                {
                    SchedulerState nextImageData = GetImageData(data, ThemeManager.currentTheme, nextImageUpdateTime.Value + TimeSpan.FromSeconds(1));

                    lock (interpolationLock)
                    {
                        interpolation.imageId1    = imageData.imageId;
                        interpolation.imageId2    = nextImageData.imageId;
                        interpolation.lastPercent = -1;
                        interpolation.startTick   = imageData.startTick;
                        interpolation.endTick     = imageData.endTick;
                        lastImagePath             = null;
                        UpdateInterpolation();
                    }
                }
                else
                {
                    SetWallpaper(imageData.imageId);
                }
            }

            ScriptManager.RunScripts(new ScriptArgs
            {
                daySegment2 = imageData.daySegment2,
                daySegment4 = imageData.daySegment4,
                imagePath   = (ThemeManager.currentTheme != null) ? lastImagePath : null
            });

            if (data.polarPeriod != PolarPeriod.None)
            {
                nextUpdateTime = DateTime.Today.AddDays(1);
            }
            else if (isSunUp)
            {
                nextUpdateTime = data.sunsetTime;
            }
            else if (DateTime.Now < data.solarTimes[0])
            {
                nextUpdateTime = data.sunriseTime;
            }
            else
            {
                SolarData tomorrowsData = SunriseSunsetService.GetSolarData(DateTime.Today.AddDays(1));
                nextUpdateTime = tomorrowsData.sunriseTime;
            }

            if (nextImageUpdateTime.HasValue && nextImageUpdateTime.Value < nextUpdateTime.Value)
            {
                nextUpdateTime = nextImageUpdateTime;
            }

            StartTimer(nextUpdateTime.Value);
        }
Example #18
0
        public void RunScheduler(bool forceImageUpdate = false)
        {
            if (!LaunchSequence.IsLocationReady() || !LaunchSequence.IsThemeReady())
            {
                return;
            }

            schedulerTimer.Stop();
            DateTimeTZ DateTimeToday = DateTimeTZ.UTC.Today.ConvertTime(JsonConfig.settings.timezone);
            SolarData  data          = SunriseSunsetService.GetSolarData(DateTimeToday);
            DateTimeTZ DateTimeNow   = DateTimeTZ.UTC.Now.ConvertTime(JsonConfig.settings.timezone);

            isSunUp = (data.sunriseTime.Time <= DateTimeNow.Time && DateTimeNow.Time < data.sunsetTime.Time);

            DateTime?nextImageUpdateTime = null;

            if (ThemeManager.currentTheme != null)
            {
                if (forceImageUpdate)
                {
                    lastImagePath = null;
                }

                WallpaperShuffler.MaybeShuffleWallpaper();
            }

            SchedulerState imageData = GetImageData(data, ThemeManager.currentTheme, DateTimeNow);

            if (ThemeManager.currentTheme != null)
            {
                SetWallpaper(imageData.imageId);
                nextImageUpdateTime = new DateTimeTZ(JsonConfig.settings.timezone, new DateTime(imageData.nextUpdateTicks)).Time;
            }

            ScriptManager.RunScripts(new ScriptArgs
            {
                daySegment2 = imageData.daySegment2,
                daySegment4 = imageData.daySegment4,
                imagePath   = (ThemeManager.currentTheme != null) ? lastImagePath : null
            });

            if (data.polarPeriod != PolarPeriod.None)
            {
                nextUpdateTime = DateTimeToday.AddDays(1).Time;
            }
            else if (isSunUp)
            {
                nextUpdateTime = data.sunsetTime.Time;
            }
            else if (DateTimeNow.Time < data.solarTimes[0].Time)
            {
                nextUpdateTime = data.sunriseTime.Time;
            }
            else
            {
                SolarData tomorrowsData = SunriseSunsetService.GetSolarData(DateTimeToday.AddDays(1));
                nextUpdateTime = tomorrowsData.sunriseTime.Time;
            }

            if (nextImageUpdateTime.HasValue && nextImageUpdateTime.Value < nextUpdateTime.Value)
            {
                nextUpdateTime = nextImageUpdateTime;
            }

            StartTimer(nextUpdateTime.Value);
        }
Example #19
0
        public static List <DateTime> GetAllImageTimes(ThemeConfig theme)
        {
            List <DateTime> times    = new List <DateTime>();
            SolarData       data     = SunriseSunsetService.GetSolarData(DateTime.Today);
            SolarData       nextData = SunriseSunsetService.GetSolarData(DateTime.Today.AddDays(1));

            if (data.polarPeriod != PolarPeriod.None)
            {
                if (theme.sunriseImageList != null)
                {
                    for (int i = 0; i < theme.sunriseImageList.Length; i++)
                    {
                        times.Add(DateTime.MinValue);
                    }
                }
                for (int i = 0; i < theme.dayImageList.Length; i++)
                {
                    if (data.polarPeriod == PolarPeriod.PolarDay)
                    {
                        times.Add(DateTime.Today + TimeSpan.FromTicks(TimeSpan.FromDays(1).Ticks *i / theme.dayImageList.Length));
                    }
                    else
                    {
                        times.Add(DateTime.MinValue);
                    }
                }
                if (theme.sunsetImageList != null)
                {
                    for (int i = 0; i < theme.sunsetImageList.Length; i++)
                    {
                        times.Add(DateTime.MinValue);
                    }
                }
                for (int i = 0; i < theme.nightImageList.Length; i++)
                {
                    if (data.polarPeriod == PolarPeriod.PolarNight)
                    {
                        times.Add(DateTime.Today + TimeSpan.FromTicks(TimeSpan.FromDays(1).Ticks *i / theme.nightImageList.Length));
                    }
                    else
                    {
                        times.Add(DateTime.MinValue);
                    }
                }
            }
            else if (ThemeManager.IsTheme4Segment(theme))
            {
                for (int i = 0; i < theme.sunriseImageList.Length; i++)
                {
                    times.Add(data.solarTimes[0] + TimeSpan.FromTicks((data.solarTimes[1].Ticks - data.solarTimes[0].Ticks) * i / theme.sunriseImageList.Length));
                }
                for (int i = 0; i < theme.dayImageList.Length; i++)
                {
                    times.Add(data.solarTimes[1] + TimeSpan.FromTicks((data.solarTimes[2].Ticks - data.solarTimes[1].Ticks) * i / theme.dayImageList.Length));
                }
                for (int i = 0; i < theme.sunsetImageList.Length; i++)
                {
                    times.Add(data.solarTimes[2] + TimeSpan.FromTicks((data.solarTimes[3].Ticks - data.solarTimes[2].Ticks) * i / theme.sunsetImageList.Length));
                }
                for (int i = 0; i < theme.nightImageList.Length; i++)
                {
                    times.Add(data.solarTimes[3] + TimeSpan.FromTicks((nextData.solarTimes[0].Ticks - data.solarTimes[3].Ticks) * i / theme.nightImageList.Length));
                }
            }
            else
            {
                for (int i = 0; i < theme.dayImageList.Length; i++)
                {
                    times.Add(data.sunriseTime + TimeSpan.FromTicks((data.sunsetTime.Ticks - data.sunriseTime.Ticks) * i / theme.dayImageList.Length));
                }
                for (int i = 0; i < theme.nightImageList.Length; i++)
                {
                    times.Add(data.sunsetTime + TimeSpan.FromTicks((nextData.sunriseTime.Ticks - data.sunsetTime.Ticks) * i / theme.nightImageList.Length));
                }
            }

            return(times);
        }
Example #20
0
        public void RunScheduler(bool forceImageUpdate = false)
        {
            schedulerTimer.Stop();

            SolarData  data = SunriseSunsetService.GetSolarData(DateTime.Today);
            DaySegment currentSegment;

            if (data.solarTimes[0] <= DateTime.Now && DateTime.Now < data.solarTimes[1])
            {
                currentSegment = DaySegment.Sunrise;
            }
            else if (data.solarTimes[1] <= DateTime.Now && DateTime.Now < data.solarTimes[2])
            {
                currentSegment = DaySegment.Day;
            }
            else if (data.solarTimes[2] <= DateTime.Now && DateTime.Now < data.solarTimes[3])
            {
                currentSegment = DaySegment.Sunset;
            }
            else
            {
                currentSegment = DaySegment.Night;
            }

            isSunUp = (data.sunriseTime <= DateTime.Now && DateTime.Now < data.sunsetTime);
            DateTime?nextImageUpdateTime = null;

            if (ThemeManager.currentTheme != null)
            {
                if (forceImageUpdate)
                {
                    lastImagePath = null;
                }

                nextImageUpdateTime = UpdateImage(data, currentSegment);
            }

            SystemThemeChanger.TryUpdateSystemTheme();

            if (isSunUp)
            {
                nextUpdateTime = data.sunsetTime;
            }
            else if (DateTime.Now < data.solarTimes[0])
            {
                nextUpdateTime = data.sunriseTime;
            }
            else
            {
                SolarData tomorrowsData = SunriseSunsetService.GetSolarData(
                    DateTime.Today.AddDays(1));
                nextUpdateTime = tomorrowsData.sunriseTime;
            }

            if (nextImageUpdateTime.HasValue && nextImageUpdateTime.Value < nextUpdateTime.Value)
            {
                nextUpdateTime = nextImageUpdateTime;
            }

            StartTimer(nextUpdateTime.Value);
            JsonConfig.SaveConfig();
        }