diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index 1f0c884..fecfdb7 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -1,7 +1,8 @@ //! Integrations for cosmic-config — the cosmic configuration system. use notify::{ - event::{EventKind, ModifyKind}, RecommendedWatcher, Watcher + event::{EventKind, ModifyKind}, + RecommendedWatcher, Watcher, }; use notify_debouncer_full::{DebouncedEvent, Debouncer, RecommendedCache}; use serde::{de::DeserializeOwned, Serialize}; @@ -9,7 +10,8 @@ use std::{ fmt, fs, io::Write, path::{Path, PathBuf}, - sync::Mutex, time::Duration, + sync::Mutex, + time::Duration, }; #[cfg(feature = "subscription")] @@ -255,46 +257,50 @@ impl Config { return Err(Error::NoConfigDirectory); }; let user_path_clone = user_path.clone(); - let mut watcher = - notify_debouncer_full::new_debouncer(Duration::from_secs(1), None, move |event_res: Result, Vec>| { + let mut watcher = notify_debouncer_full::new_debouncer( + Duration::from_secs(1), + None, + move |event_res: Result, Vec>| { match event_res { Ok(events) => { for event in events { match &event.event.kind { - EventKind::Access(_) | EventKind::Modify(ModifyKind::Metadata(_)) => { - // Data not mutated - return; + EventKind::Access(_) + | EventKind::Modify(ModifyKind::Metadata(_)) => { + // Data not mutated + return; + } + _ => {} } - _ => {} - } - let mut keys = Vec::new(); - for path in &event.paths { - match path.strip_prefix(&user_path_clone) { - Ok(key_path) => { - if let Some(key) = key_path.to_str() { - // Skip any .atomicwrite temporary files - if key.starts_with(".atomicwrite") { - continue; + let mut keys = Vec::new(); + for path in &event.paths { + match path.strip_prefix(&user_path_clone) { + Ok(key_path) => { + if let Some(key) = key_path.to_str() { + // Skip any .atomicwrite temporary files + if key.starts_with(".atomicwrite") { + continue; + } + keys.push(key.to_string()); } - keys.push(key.to_string()); + } + Err(_err) => { + //TODO: handle errors } } - Err(_err) => { - //TODO: handle errors - } } - } - if !keys.is_empty() { - f(&watch_config, &keys); - } + if !keys.is_empty() { + f(&watch_config, &keys); + } } } Err(_errs) => { //TODO: handle errors } } - })?; + }, + )?; watcher.watch(user_path, notify::RecursiveMode::NonRecursive)?; Ok(watcher) } diff --git a/cosmic-config/src/subscription.rs b/cosmic-config/src/subscription.rs index 591b85e..2d2c511 100644 --- a/cosmic-config/src/subscription.rs +++ b/cosmic-config/src/subscription.rs @@ -8,7 +8,12 @@ use crate::{Config, CosmicConfigEntry}; pub enum ConfigState { Init(Cow<'static, str>, u64, bool), - Waiting(T, Debouncer, mpsc::Receiver>, Config), + Waiting( + T, + Debouncer, + mpsc::Receiver>, + Config, + ), Failed, } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 7fbb5ba..5e335f5 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -85,33 +85,33 @@ pub fn is_high_contrast() -> bool { active_type().is_high_contrast() } -/// Watches for changes to the system's theme preference. -#[cold] -pub fn subscription(is_dark: bool) -> Subscription { - config_subscription::<_, crate::cosmic_theme::Theme>( - ( - std::any::TypeId::of::(), - is_dark, - ), - if is_dark { - cosmic_theme::DARK_THEME_ID - } else { - cosmic_theme::LIGHT_THEME_ID - } - .into(), - crate::cosmic_theme::Theme::VERSION, - ) - .map(|res| { - for error in res.errors.into_iter().filter(cosmic_config::Error::is_err) { - tracing::error!( - ?error, - "error while watching system theme preference changes" - ); - } +// /// Watches for changes to the system's theme preference. +// #[cold] +// pub fn subscription(is_dark: bool) -> Subscription { +// config_subscription::<_, crate::cosmic_theme::Theme>( +// ( +// std::any::TypeId::of::(), +// is_dark, +// ), +// if is_dark { +// cosmic_theme::DARK_THEME_ID +// } else { +// cosmic_theme::LIGHT_THEME_ID +// } +// .into(), +// crate::cosmic_theme::Theme::VERSION, +// ) +// .map(|res| { +// for error in res.errors.into_iter().filter(cosmic_config::Error::is_err) { +// tracing::error!( +// ?error, +// "error while watching system theme preference changes" +// ); +// } - Theme::system(Arc::new(res.config)) - }) -} +// Theme::system(Arc::new(res.config)) +// }) +// } pub fn system_dark() -> Theme { let Ok(helper) = crate::cosmic_theme::Theme::dark_config() else {