use std::path::Path;
use notify::{RecursiveMode, Watcher};
use tokio::sync::broadcast;
fn is_cache_path(p: &Path) -> bool {
p.components().any(|c| c.as_os_str() == ".cache")
}
pub fn spawn(
dir: &Path,
tx: broadcast::Sender<String>,
) -> notify::Result<notify::RecommendedWatcher> {
let mut watcher = notify::recommended_watcher(move |res: notify::Result<notify::Event>| {
if let Ok(event) = res {
let only_cache =
!event.paths.is_empty() && event.paths.iter().all(|p| is_cache_path(p));
if only_cache {
return;
}
let _ = tx.send("changed".to_string());
}
})?;
watcher.watch(dir, RecursiveMode::Recursive)?;
Ok(watcher)
}