diff --git a/Cargo.toml b/Cargo.toml index 14fa8454..8a2285d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ sctk = { package = "smithay-client-toolkit", git = "https://github.com/pop-os/cl slotmap = "1.0.6" fraction = "0.13.0" cosmic-config = { path = "cosmic-config" } +tracing = "0.1" [target.'cfg(unix)'.dependencies] freedesktop-icons = "0.2.2" diff --git a/cosmic-theme/src/model/theme.rs b/cosmic-theme/src/model/theme.rs index 51412998..284dd6c6 100644 --- a/cosmic-theme/src/model/theme.rs +++ b/cosmic-theme/src/model/theme.rs @@ -151,7 +151,7 @@ pub trait LayeredTheme { impl Theme { /// version of the theme - pub fn version() -> u32 { + pub fn version() -> u64 { 1 } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index bf1074b9..231d5faa 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -11,9 +11,13 @@ use std::sync::Arc; pub use self::segmented_button::SegmentedButton; +use cosmic_config::config_subscription; +use cosmic_config::CosmicConfigEntry; +use cosmic_theme::util::CssColor; use cosmic_theme::Component; use cosmic_theme::LayeredTheme; use iced_core::renderer::BorderRadius; +use iced_futures::Subscription; use iced_style::application; use iced_style::button; use iced_style::checkbox; @@ -1112,3 +1116,42 @@ impl text_input::StyleSheet for Theme { todo!() } } + +pub fn theme() -> Theme { + let Ok(helper) = crate::cosmic_config::Config::new( + crate::cosmic_theme::NAME, + crate::cosmic_theme::Theme::::version(), + ) else { + return crate::theme::Theme::dark(); + }; + let t = crate::cosmic_theme::Theme::get_entry(&helper).map_or_else( + |(errors, theme)| { + for err in errors { + tracing::error!("{:?}", err); + } + theme.into_srgba() + }, + crate::cosmic_theme::Theme::into_srgba, + ); + crate::theme::Theme::custom(Arc::new(t)) +} + +pub fn theme_subscription(id: u64) -> Subscription { + config_subscription::>( + id, + crate::cosmic_theme::NAME.into(), + crate::cosmic_theme::Theme::::version(), + ) + .map(|(_, res)| { + let theme = res.map_or_else( + |(errors, theme)| { + for err in errors { + tracing::error!("{:?}", err); + } + theme.into_srgba() + }, + crate::cosmic_theme::Theme::into_srgba, + ); + crate::theme::Theme::custom(Arc::new(theme)) + }) +}