private static string GetCarouselItems(SchedulerState wpState, ThemeConfig theme) { List <string> lines = new List <string>(); int imageCount = Directory.EnumerateFiles(Path.Combine("assets", "images"), theme.themeId + "_*.jpg").Count(); int activeImage = (imageCount == 2) ? (wpState.daySegment2 * 2 + 1) : wpState.daySegment4; for (int i = 0; i < sunPhases.Length; i++) { if (imageCount == 2 && i % 2 == 0) { continue; } if (i == activeImage) { lines.Add("<div class=\"carousel-item active\">"); } else { lines.Add("<div class=\"carousel-item\">"); } string imageFilename = theme.themeId + "_" + sunPhases[i].ToLower() + ".jpg"; string imagePath = Path.Combine("assets", "images", imageFilename).Replace(@"\", "/"); lines.Add(string.Format(" <img src=\"{0}\" alt=\"{1}\">", imagePath, translatedSunPhases[i])); lines.Add("</div>"); } return(string.Join(Environment.NewLine, lines)); }
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); }
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)); }
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); }
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 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); }
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); }
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); }
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); }