chore: format

This commit is contained in:
Michael Aaron Murphy 2025-06-23 17:50:28 +02:00
parent 90ad3e9e1b
commit 1af2f4ffe5
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
3 changed files with 64 additions and 53 deletions

View file

@ -1,7 +1,8 @@
//! Integrations for cosmic-config — the cosmic configuration system. //! Integrations for cosmic-config — the cosmic configuration system.
use notify::{ use notify::{
event::{EventKind, ModifyKind}, RecommendedWatcher, Watcher event::{EventKind, ModifyKind},
RecommendedWatcher, Watcher,
}; };
use notify_debouncer_full::{DebouncedEvent, Debouncer, RecommendedCache}; use notify_debouncer_full::{DebouncedEvent, Debouncer, RecommendedCache};
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
@ -9,7 +10,8 @@ use std::{
fmt, fs, fmt, fs,
io::Write, io::Write,
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Mutex, time::Duration, sync::Mutex,
time::Duration,
}; };
#[cfg(feature = "subscription")] #[cfg(feature = "subscription")]
@ -255,46 +257,50 @@ impl Config {
return Err(Error::NoConfigDirectory); return Err(Error::NoConfigDirectory);
}; };
let user_path_clone = user_path.clone(); let user_path_clone = user_path.clone();
let mut watcher = let mut watcher = notify_debouncer_full::new_debouncer(
notify_debouncer_full::new_debouncer(Duration::from_secs(1), None, move |event_res: Result<Vec<DebouncedEvent>, Vec<notify::Error>>| { Duration::from_secs(1),
None,
move |event_res: Result<Vec<DebouncedEvent>, Vec<notify::Error>>| {
match event_res { match event_res {
Ok(events) => { Ok(events) => {
for event in events { for event in events {
match &event.event.kind { match &event.event.kind {
EventKind::Access(_) | EventKind::Modify(ModifyKind::Metadata(_)) => { EventKind::Access(_)
// Data not mutated | EventKind::Modify(ModifyKind::Metadata(_)) => {
return; // Data not mutated
return;
}
_ => {}
} }
_ => {}
}
let mut keys = Vec::new(); let mut keys = Vec::new();
for path in &event.paths { for path in &event.paths {
match path.strip_prefix(&user_path_clone) { match path.strip_prefix(&user_path_clone) {
Ok(key_path) => { Ok(key_path) => {
if let Some(key) = key_path.to_str() { if let Some(key) = key_path.to_str() {
// Skip any .atomicwrite temporary files // Skip any .atomicwrite temporary files
if key.starts_with(".atomicwrite") { if key.starts_with(".atomicwrite") {
continue; 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() {
if !keys.is_empty() { f(&watch_config, &keys);
f(&watch_config, &keys); }
}
} }
} }
Err(_errs) => { Err(_errs) => {
//TODO: handle errors //TODO: handle errors
} }
} }
})?; },
)?;
watcher.watch(user_path, notify::RecursiveMode::NonRecursive)?; watcher.watch(user_path, notify::RecursiveMode::NonRecursive)?;
Ok(watcher) Ok(watcher)
} }

View file

@ -8,7 +8,12 @@ use crate::{Config, CosmicConfigEntry};
pub enum ConfigState<T> { pub enum ConfigState<T> {
Init(Cow<'static, str>, u64, bool), Init(Cow<'static, str>, u64, bool),
Waiting(T, Debouncer<RecommendedWatcher, RecommendedCache>, mpsc::Receiver<Vec<String>>, Config), Waiting(
T,
Debouncer<RecommendedWatcher, RecommendedCache>,
mpsc::Receiver<Vec<String>>,
Config,
),
Failed, Failed,
} }

View file

@ -85,33 +85,33 @@ pub fn is_high_contrast() -> bool {
active_type().is_high_contrast() active_type().is_high_contrast()
} }
/// Watches for changes to the system's theme preference. // /// Watches for changes to the system's theme preference.
#[cold] // #[cold]
pub fn subscription(is_dark: bool) -> Subscription<crate::theme::Theme> { // pub fn subscription(is_dark: bool) -> Subscription<crate::theme::Theme> {
config_subscription::<_, crate::cosmic_theme::Theme>( // config_subscription::<_, crate::cosmic_theme::Theme>(
( // (
std::any::TypeId::of::<crate::cosmic_theme::Theme>(), // std::any::TypeId::of::<crate::cosmic_theme::Theme>(),
is_dark, // is_dark,
), // ),
if is_dark { // if is_dark {
cosmic_theme::DARK_THEME_ID // cosmic_theme::DARK_THEME_ID
} else { // } else {
cosmic_theme::LIGHT_THEME_ID // cosmic_theme::LIGHT_THEME_ID
} // }
.into(), // .into(),
crate::cosmic_theme::Theme::VERSION, // crate::cosmic_theme::Theme::VERSION,
) // )
.map(|res| { // .map(|res| {
for error in res.errors.into_iter().filter(cosmic_config::Error::is_err) { // for error in res.errors.into_iter().filter(cosmic_config::Error::is_err) {
tracing::error!( // tracing::error!(
?error, // ?error,
"error while watching system theme preference changes" // "error while watching system theme preference changes"
); // );
} // }
Theme::system(Arc::new(res.config)) // Theme::system(Arc::new(res.config))
}) // })
} // }
pub fn system_dark() -> Theme { pub fn system_dark() -> Theme {
let Ok(helper) = crate::cosmic_theme::Theme::dark_config() else { let Ok(helper) = crate::cosmic_theme::Theme::dark_config() else {