Añade soporte a temas en la API de extensiones

- Incluye una opción de configuración para definir el tema por defecto.
- Añade un tema básico predeterminado.
This commit is contained in:
Manuel Cillero 2025-07-20 23:51:15 +02:00
parent e6c59b8579
commit f2d9fff0c3
13 changed files with 148 additions and 5 deletions

31
src/core/theme/all.rs Normal file
View file

@ -0,0 +1,31 @@
use crate::core::theme::ThemeRef;
use crate::global;
use std::sync::{LazyLock, RwLock};
// TEMAS *******************************************************************************************
pub static THEMES: LazyLock<RwLock<Vec<ThemeRef>>> = LazyLock::new(|| RwLock::new(Vec::new()));
// TEMA PREDETERMINADO *****************************************************************************
pub static DEFAULT_THEME: LazyLock<ThemeRef> =
LazyLock::new(|| match theme_by_short_name(&global::SETTINGS.app.theme) {
Some(theme) => theme,
None => &crate::base::theme::Basic,
});
// TEMA POR NOMBRE *********************************************************************************
pub fn theme_by_short_name(short_name: impl AsRef<str>) -> Option<ThemeRef> {
let short_name = short_name.as_ref().to_lowercase();
match THEMES
.read()
.unwrap()
.iter()
.find(|t| t.short_name().to_lowercase() == short_name)
{
Some(theme) => Some(*theme),
_ => None,
}
}