private static void ApplyTheme(AdmConfig config, Theme newTheme, bool automatic, DateTime sunset, DateTime sunrise) { RuntimeConfig rtc = RuntimeConfig.Instance(); if (config.DarkThemePath == null || config.LightThemePath == null) { Logger.Error("dark or light theme path empty"); return; } if (!File.Exists(config.DarkThemePath)) { Logger.Error($"invalid dark theme path: {config.DarkThemePath}"); return; } if (!File.Exists(config.LightThemePath)) { Logger.Error($"invalid light theme path : {config.LightThemePath}"); return; } if (!config.DarkThemePath.EndsWith(".theme") || !config.DarkThemePath.EndsWith(".theme")) { Logger.Error("both theme paths must have a .theme extension"); return; } if (Path.GetFileNameWithoutExtension(config.DarkThemePath) != rtc.CurrentWindowsThemeName && newTheme == Theme.Dark) { if (automatic) { Logger.Info($"automatic dark theme switch pending, sunset: {sunset.ToString("HH:mm:ss")}"); } else { Logger.Info("switching to dark theme"); } SetColorFilter(config.ColorFilterEnabled, newTheme); SetOfficeTheme(config.Office.Mode, newTheme, rtc, config.Office.LightTheme, config.Office.DarkTheme, config.Office.Enabled); ThemeHandler.Apply(config.DarkThemePath); } else if (Path.GetFileNameWithoutExtension(config.LightThemePath) != rtc.CurrentWindowsThemeName && newTheme == Theme.Light) { if (automatic) { Logger.Info($"automatic light theme switch pending, sunrise: {sunrise.ToString("HH:mm:ss")}"); } else { Logger.Info("switching to light theme"); } SetColorFilter(config.ColorFilterEnabled, newTheme); SetOfficeTheme(config.Office.Mode, newTheme, rtc, config.Office.LightTheme, config.Office.DarkTheme, config.Office.Enabled); ThemeHandler.Apply(config.LightThemePath); } }
/// <summary> /// Applies the theme using the KAWAII Theme switcher logic for windows theme files /// </summary> /// <param name="config"></param> /// <param name="newTheme"></param> /// <param name="automatic"></param> /// <param name="sunset"></param> /// <param name="sunrise"></param> /// <returns>true if an update was performed; false otherwise</returns> private static bool ApplyTheme(AdmConfig config, Theme newTheme) { GlobalState state = GlobalState.Instance(); if (config.WindowsThemeMode.DarkThemePath == null || config.WindowsThemeMode.LightThemePath == null) { Logger.Error("dark or light theme path empty"); return(false); } if (!File.Exists(config.WindowsThemeMode.DarkThemePath)) { Logger.Error($"invalid dark theme path: {config.WindowsThemeMode.DarkThemePath}"); return(false); } if (!File.Exists(config.WindowsThemeMode.LightThemePath)) { Logger.Error($"invalid light theme path: {config.WindowsThemeMode.LightThemePath}"); return(false); } if (!config.WindowsThemeMode.DarkThemePath.EndsWith(".theme") || !config.WindowsThemeMode.DarkThemePath.EndsWith(".theme")) { Logger.Error("both theme paths must have a .theme extension"); return(false); } // TODO change tracking when having active theme monitor disabled if (newTheme == Theme.Dark && !state.CurrentWindowsThemeName.Equals(Path.GetFileNameWithoutExtension(config.WindowsThemeMode.DarkThemePath), StringComparison.Ordinal)) { PowerHandler.DisableEnergySaver(config); ThemeHandler.Apply(config.WindowsThemeMode.DarkThemePath); return(true); } else if (newTheme == Theme.Light && !state.CurrentWindowsThemeName.Equals(Path.GetFileNameWithoutExtension(config.WindowsThemeMode.LightThemePath), StringComparison.Ordinal)) { PowerHandler.DisableEnergySaver(config); ThemeHandler.Apply(config.WindowsThemeMode.LightThemePath); return(true); } return(false); }