I am trying to create a filewatcher in rust using the notify-crate. Since I don't want it to spam all events but rather just tell once if a change occured I tried using a debounced filewatcher:
pub fn create_watcher(path: &str) -> Result<(ReadDirectoryChangesWatcher, Receiver<DebouncedEvent>), notify::Error> {
let (sender, receiver) = channel();
// should debounce for 10s
let mut watcher = watcher(sender, Duration::from_secs(10))?;
watcher.watch(path, RecursiveMode::Recursive)?;
Ok((watcher, receiver))
}
Yet it still creates an event for every operation it notices. The usage of the function can be seen below:
#[tauri::command]
fn listen_installed(window: Window) {
thread::spawn(move || {
let username = env::var("USERNAME").unwrap();
let channel = create_watcher(&format!("C:\\Users\\{}\\scoop\\apps", username)).unwrap();
loop {
match channel.1.recv() {
Ok(ok) => {
window.emit("installed-packages-changed", None::<&str>);
},
Err(e) => println!("{:?}", &e.to_string()),
};
}
});
}
Haven't I used the file-watcher properly or did I missunderstand what a "Debounced-Watcher" is?