diff --git a/cosmic-config/Cargo.toml b/cosmic-config/Cargo.toml index 424ea262..a79237c8 100644 --- a/cosmic-config/Cargo.toml +++ b/cosmic-config/Cargo.toml @@ -26,7 +26,6 @@ dirs.workspace = true tokio = { version = "1.44", optional = true, features = ["time"] } async-std = { version = "1.13", optional = true } tracing = "0.1" -notify-debouncer-full = "0.5.0" [target.'cfg(unix)'.dependencies] xdg = "2.5" diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index fecfdb75..0f846562 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -4,7 +4,6 @@ use notify::{ event::{EventKind, ModifyKind}, RecommendedWatcher, Watcher, }; -use notify_debouncer_full::{DebouncedEvent, Debouncer, RecommendedCache}; use serde::{de::DeserializeOwned, Serialize}; use std::{ fmt, fs, @@ -246,7 +245,7 @@ impl Config { // This may end up being an mpsc channel instead of a function // See EventHandler in the notify crate: https://docs.rs/notify/latest/notify/trait.EventHandler.html // Having a callback allows for any application abstraction to be used - pub fn watch(&self, f: F) -> Result, Error> + pub fn watch(&self, f: F) -> Result // Argument is an array of all keys that changed in that specific transaction //TODO: simplify F requirements where @@ -257,51 +256,47 @@ 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::recommended_watcher( + move |event_res: Result| { match event_res { - Ok(events) => { - for event in events { - match &event.event.kind { - EventKind::Access(_) - | EventKind::Modify(ModifyKind::Metadata(_)) => { - // Data not mutated - return; - } - _ => {} + Ok(event) => { + match &event.kind { + 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; - } - keys.push(key.to_string()); + 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; } - } - Err(_err) => { - //TODO: handle errors + keys.push(key.to_string()); } } - } - if !keys.is_empty() { - f(&watch_config, &keys); + Err(_err) => { + //TODO: handle errors + } } } + if !keys.is_empty() { + f(&watch_config, &keys); + } } - Err(_errs) => { + Err(_err) => { //TODO: handle errors } } }, )?; - watcher.watch(user_path, notify::RecursiveMode::NonRecursive)?; + watcher.watch(user_path, notify::RecursiveMode::Recursive)?; Ok(watcher) } diff --git a/cosmic-config/src/subscription.rs b/cosmic-config/src/subscription.rs index 2d2c5117..3e54c1c3 100644 --- a/cosmic-config/src/subscription.rs +++ b/cosmic-config/src/subscription.rs @@ -1,7 +1,6 @@ use iced_futures::futures::{SinkExt, Stream}; use iced_futures::{futures::channel::mpsc, stream}; use notify::RecommendedWatcher; -use notify_debouncer_full::{Debouncer, RecommendedCache}; use std::{borrow::Cow, hash::Hash}; use crate::{Config, CosmicConfigEntry}; @@ -10,7 +9,7 @@ pub enum ConfigState { Init(Cow<'static, str>, u64, bool), Waiting( T, - Debouncer, + RecommendedWatcher, mpsc::Receiver>, Config, ),