From d92a8a0e16eda3df7566e5c995aa0d258b6b76f7 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 15 Nov 2022 09:10:08 -0500 Subject: Update to notify v5 via notify_debouncer_mini Notify v5 moved the debounced API into the notify_debouncer_mini crate. The debounced API doesn't provide details on the type of event that happened, just that a list of events or errors happened. Therefore, reload is triggered on any event for a matching path. Co-authored-by: Christian Duerr --- alacritty/src/config/monitor.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/config/monitor.rs b/alacritty/src/config/monitor.rs index f6d52e2f..622a993b 100644 --- a/alacritty/src/config/monitor.rs +++ b/alacritty/src/config/monitor.rs @@ -3,7 +3,8 @@ use std::sync::mpsc; use std::time::Duration; use log::{debug, error}; -use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; +use notify_debouncer_mini::new_debouncer; +use notify_debouncer_mini::notify::RecursiveMode; use winit::event_loop::EventLoopProxy; use alacritty_terminal::thread; @@ -40,8 +41,8 @@ pub fn watch(mut paths: Vec, event_proxy: EventLoopProxy) { // The Duration argument is a debouncing period. let (tx, rx) = mpsc::channel(); - let mut watcher = match watcher(tx, DEBOUNCE_DELAY) { - Ok(watcher) => watcher, + let mut debouncer = match new_debouncer(DEBOUNCE_DELAY, None, tx) { + Ok(debouncer) => debouncer, Err(err) => { error!("Unable to watch config file: {}", err); return; @@ -61,6 +62,7 @@ pub fn watch(mut paths: Vec, event_proxy: EventLoopProxy) { parents.sort_unstable(); parents.dedup(); + let watcher = debouncer.watcher(); // Watch all configuration file directories. for parent in &parents { if let Err(err) = watcher.watch(parent, RecursiveMode::NonRecursive) { @@ -69,26 +71,22 @@ pub fn watch(mut paths: Vec, event_proxy: EventLoopProxy) { } loop { - let event = match rx.recv() { - Ok(event) => event, + let events = match rx.recv() { + Ok(Ok(events)) => events, + Ok(Err(err)) => { + debug!("Config watcher errors: {:?}", err); + continue; + }, Err(err) => { debug!("Config watcher channel dropped unexpectedly: {}", err); break; }, }; - match event { - DebouncedEvent::Rename(_, path) - | DebouncedEvent::Write(path) - | DebouncedEvent::Create(path) - | DebouncedEvent::Chmod(path) - if paths.contains(&path) => - { - // Always reload the primary configuration file. - let event = Event::new(EventType::ConfigReload(paths[0].clone()), None); - let _ = event_proxy.send_event(event); - }, - _ => (), + if events.iter().any(|e| paths.contains(&e.path)) { + // Always reload the primary configuration file. + let event = Event::new(EventType::ConfigReload(paths[0].clone()), None); + let _ = event_proxy.send_event(event); } } }); -- cgit