public static void RequestSwitch(AdmConfigBuilder builder, SwitchEventArgs e) { if (state.ForcedTheme == Theme.Dark) { UpdateTheme(builder.Config, Theme.Dark, e); return; } else if (state.ForcedTheme == Theme.Light) { UpdateTheme(builder.Config, Theme.Light, e); return; } if (builder.Config.Events.DarkThemeOnBattery) { if (PowerManager.BatteryStatus == BatteryStatus.Discharging) { UpdateTheme(builder.Config, Theme.Dark, e); return; } if (!builder.Config.AutoThemeSwitchingEnabled) { UpdateTheme(builder.Config, Theme.Light, e); return; } } if (builder.Config.AutoThemeSwitchingEnabled) { DateTime sunrise = builder.Config.Sunrise; DateTime sunset = builder.Config.Sunset; if (builder.Config.Location.Enabled) { LocationHandler.GetSunTimes(builder, out sunrise, out sunset); } //the time bewteen sunrise and sunset, aka "day" if (Extensions.NowIsBetweenTimes(sunrise.TimeOfDay, sunset.TimeOfDay)) { UpdateTheme(builder.Config, Theme.Light, e, sunrise); } else { UpdateTheme(builder.Config, Theme.Dark, e, sunset); } } else { UpdateTheme(builder.Config, state.LastRequestedTheme, e); } }
public override void Fire() { Task.Run(async() => { DateTime sunriseMonitor = ConfigBuilder.Config.Sunrise; DateTime sunsetMonitor = ConfigBuilder.Config.Sunset; if (ConfigBuilder.Config.Location.Enabled) { LocationHandler.GetSunTimes(ConfigBuilder, out sunriseMonitor, out sunsetMonitor); } //the time between sunrise and sunset, aka "day" if (Extensions.NowIsBetweenTimes(sunriseMonitor.TimeOfDay, sunsetMonitor.TimeOfDay)) { if (SuntimeIsWithinSpan(sunsetMonitor)) { if (!PostponeDark) { Logger.Info($"starting GPU usage monitoring, theme switch pending within {Math.Abs(ConfigBuilder.Config.GPUMonitoring.MonitorTimeSpanMin)} minute(s)"); State.PostponeSwitch = true; PostponeDark = true; } } // if it's already light, check if the theme switch from dark to light should be delayed else if (PostponeLight && DateTime.Now >= sunriseMonitor) { var result = await CheckForPostpone(); if (result != ThreshHigh) { PostponeLight = false; } } else { if (PostponeDark || PostponeLight) { Logger.Info($"ending GPU usage monitoring"); PostponeDark = false; PostponeLight = false; State.PostponeSwitch = false; } } } // the time between sunset and sunrise, aka "night" else { if (SuntimeIsWithinSpan(sunriseMonitor)) { if (!PostponeLight) { Logger.Info($"starting GPU usage monitoring, theme switch pending within {Math.Abs(ConfigBuilder.Config.GPUMonitoring.MonitorTimeSpanMin)} minute(s)"); State.PostponeSwitch = true; PostponeLight = true; } } // if it's already dark, check if the theme switch from light to dark should be delayed else if (PostponeDark && DateTime.Now >= sunsetMonitor) { var result = await CheckForPostpone(); if (result != ThreshHigh) { PostponeDark = false; } } else { if (PostponeDark || PostponeLight) { Logger.Info($"ending GPU usage monitoring"); PostponeDark = false; PostponeLight = false; State.PostponeSwitch = false; } } } }); }