private static void ApplyThemeOptions(AdmConfig config, Theme newTheme, bool automatic, DateTime sunset, DateTime sunrise)
        {
            GlobalState state = GlobalState.Instance();

            if (!ThemeOptionsNeedUpdate(config, newTheme))
            {
                return;
            }
            PowerHandler.DisableEnergySaver(config);
            var oldsys = state.CurrentSystemTheme;
            var oldapp = state.CurrentAppsTheme;
            var oldedg = state.CurrentEdgeTheme;
            var oldwal = state.CurrentWallpaperTheme;
            var oldoff = state.CurrentOfficeTheme;
            var oldcol = state.ColorFilterEnabled;

            SetColorFilter(config.ColorFilterEnabled, newTheme);
            SetAppsTheme(config.AppsTheme, newTheme, state);
            SetEdgeTheme(config.EdgeTheme, newTheme, state);

            SetWallpaper(newTheme, state, config.Wallpaper.DarkThemeWallpapers, config.Wallpaper.LightThemeWallpapers, config.Wallpaper.Enabled);
            SetOfficeTheme(config.Office.Mode, newTheme, state, config.Office.LightTheme, config.Office.DarkTheme, config.Office.Enabled);
            //run async to delay at specific parts due to color prevalence not switching icons correctly
            int taskdelay = config.Tunable.AccentColorSwitchDelay;

            Task.Run(async() =>
            {
                await SetSystemTheme(config.SystemTheme, newTheme, taskdelay, state, config);

                if (automatic)
                {
                    Logger.Info($"theme switch invoked automatically. Sunrise: {sunrise.ToString("HH:mm:ss")}, Sunset: {sunset.ToString("HH:mm:ss")}");
                }
                else
                {
                    Logger.Info($"theme switch invoked manually");
                }
                PowerHandler.RestoreEnergySaver(config);
                Logger.Info($"theme: {newTheme} with modes (s:{config.SystemTheme}, a:{config.AppsTheme}, e:{config.EdgeTheme}, w:{config.Wallpaper.Enabled}, o:{config.Office.Enabled}, c:{config.ColorFilterEnabled})");
                Logger.Info($"was (s:{oldsys}, a:{oldapp}, e:{oldedg}, w:{oldwal}, o:{oldoff}, c:{oldcol})");
                Logger.Info($"is (s:{state.CurrentSystemTheme}, a:{state.CurrentAppsTheme}, e:{state.CurrentEdgeTheme}, w:{state.CurrentWallpaperTheme}, o:{state.CurrentOfficeTheme}, c:{state.ColorFilterEnabled})");
            });
        }
예제 #2
0
        public static void SwitchTheme(AdmConfig config, Theme newTheme, bool automatic = false, DateTime sunset = new DateTime(), DateTime sunrise = new DateTime())
        {
            if (!automatic && state.ForcedTheme == Theme.Unknown)
            {
                Logger.Info($"theme switch invoked manually");
            }

            bool themeModeSwitched = false;

            if (config.WindowsThemeMode.Enabled)
            {
                themeModeSwitched = ApplyTheme(config, newTheme);
            }

            // this is possibly necessary in the future if the config is internally updated and switchtheme is called before it is saved
            //cm.UpdateSettings();

            List <ISwitchComponent> componentsToUpdate = cm.GetComponentsToUpdate(newTheme);

            if (componentsToUpdate.Count > 0)
            {
                //if a theme switch did not occur, run mitigations
                if (!themeModeSwitched)
                {
                    PowerHandler.DisableEnergySaver(config);
                }
                cm.Run(componentsToUpdate, newTheme);
            }

            // disable mitigation after all components and theme switch have been executed
            if (componentsToUpdate.Count > 0 || themeModeSwitched)
            {
                if (newTheme == Theme.Light && automatic)
                {
                    Logger.Info($"automatic light theme switch performed, sunrise: {sunrise:HH:mm:ss}");
                }
                else if (newTheme == Theme.Dark && automatic)
                {
                    Logger.Info($"automatic dark theme switch performed, sunset: {sunset:HH:mm:ss}");
                }
                PowerHandler.RestoreEnergySaver(config);
            }
        }