/// <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> public static bool ApplyTheme(AdmConfig config, Theme newTheme) { 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.RequestDisableEnergySaver(config); Apply(config.WindowsThemeMode.DarkThemePath); return(true); } else if (newTheme == Theme.Light && !state.CurrentWindowsThemeName.Equals(Path.GetFileNameWithoutExtension(config.WindowsThemeMode.LightThemePath), StringComparison.Ordinal)) { PowerHandler.RequestDisableEnergySaver(config); Apply(config.WindowsThemeMode.LightThemePath); return(true); } return(false); }
public static void Apply(string themeFilePath) { Thread thread = new Thread(() => { try { PowerHandler.DisableEnergySaver(AdmConfigBuilder.Instance().Config); new ThemeManagerClass().ApplyTheme(themeFilePath); RuntimeConfig.Instance().CurrentWindowsThemeName = GetCurrentThemeName(); PowerHandler.RestoreEnergySaver(AdmConfigBuilder.Instance().Config); Logger.Info($"applied theme \"{themeFilePath}\" successfully"); } catch (Exception ex) { Logger.Error(ex, $"couldn't apply theme \"{themeFilePath}\""); } }) { Name = "COMThemeManagerThread" }; thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
public static void ApplyManagedTheme(AdmConfig config, string path) { PowerHandler.RequestDisableEnergySaver(config); Apply(path); }