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:
parent
cb288070af
commit
be98b7dd6f
2 changed files with 16 additions and 17 deletions
|
|
@ -685,23 +685,17 @@ impl Theme {
|
||||||
self.shade
|
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)> {
|
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()))?;
|
(if ThemeMode::is_dark(&Config::new(Self::id(), Self::VERSION)?)? {
|
||||||
let is_dark = ThemeMode::is_dark(&config).map_err(|e| (vec![e], Self::default()))?;
|
Self::dark_config
|
||||||
Self::get_active_with_brightness(is_dark)
|
} else {
|
||||||
}
|
Self::light_config
|
||||||
pub fn get_active_with_brightness(
|
})()
|
||||||
is_dark: bool,
|
})()
|
||||||
) -> Result<Self, (Vec<cosmic_config::Error>, Self)> {
|
.map_err(|error| (vec![error], Self::default()))
|
||||||
let config = if is_dark {
|
.and_then(|theme_config| Self::get_entry(&theme_config))
|
||||||
Self::dark_config()
|
|
||||||
} else {
|
|
||||||
Self::light_config()
|
|
||||||
}
|
|
||||||
.map_err(|e| (vec![e], Self::default()))?;
|
|
||||||
Self::get_entry(&config)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::Theme;
|
use crate::Theme;
|
||||||
use configparser::ini::Ini;
|
use configparser::ini::Ini;
|
||||||
|
use cosmic_config::CosmicConfigEntry;
|
||||||
use palette::{Mix, Srgba, blend::Compose};
|
use palette::{Mix, Srgba, blend::Compose};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
|
|
@ -92,7 +93,11 @@ impl Theme {
|
||||||
let dark = if self.is_dark {
|
let dark = if self.is_dark {
|
||||||
self.clone()
|
self.clone()
|
||||||
} else {
|
} else {
|
||||||
Self::get_active_with_brightness(false).unwrap_or_else(|_| self.clone())
|
Theme::light_config()
|
||||||
|
.ok()
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|conf| Theme::get_entry(conf).ok())
|
||||||
|
.unwrap_or_else(|| self.clone())
|
||||||
};
|
};
|
||||||
IniColors {
|
IniColors {
|
||||||
background_alternate: dark.accent.base,
|
background_alternate: dark.accent.base,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue