refactor(cosmic-theme): remove recently-added Theme::get_active_with_brightness

The added method was not necessary. Also improves the code in the get_active method.
This commit is contained in:
Michael Aaron Murphy 2026-02-18 14:18:27 +01:00
parent cb288070af
commit be98b7dd6f
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
2 changed files with 16 additions and 17 deletions

View file

@ -685,23 +685,17 @@ impl Theme {
self.shade
}
/// get the active theme
/// Get the active theme based on the current theme mode.
pub fn get_active() -> Result<Self, (Vec<cosmic_config::Error>, Self)> {
let config =
Config::new(Self::id(), Self::VERSION).map_err(|e| (vec![e], Self::default()))?;
let is_dark = ThemeMode::is_dark(&config).map_err(|e| (vec![e], Self::default()))?;
Self::get_active_with_brightness(is_dark)
}
pub fn get_active_with_brightness(
is_dark: bool,
) -> Result<Self, (Vec<cosmic_config::Error>, Self)> {
let config = if is_dark {
Self::dark_config()
} else {
Self::light_config()
}
.map_err(|e| (vec![e], Self::default()))?;
Self::get_entry(&config)
(|| {
(if ThemeMode::is_dark(&Config::new(Self::id(), Self::VERSION)?)? {
Self::dark_config
} else {
Self::light_config
})()
})()
.map_err(|error| (vec![error], Self::default()))
.and_then(|theme_config| Self::get_entry(&theme_config))
}
#[must_use]