diff options
author | Jonathan Schleußer <paradoxspiral@riseup.net> | 2017-08-30 21:34:23 +0200 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-09-05 09:07:00 -0700 |
commit | a7b50e0eb8b0888baee71e329117d38f10878b01 (patch) | |
tree | ad785690933ae6420e0b1cd16c9252fde145be69 /src/config.rs | |
parent | a3d35ec1859802a2440d29ac24d87bf347a6144e (diff) | |
download | alacritty-a7b50e0eb8b0888baee71e329117d38f10878b01.tar.gz alacritty-a7b50e0eb8b0888baee71e329117d38f10878b01.zip |
Update notify
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/src/config.rs b/src/config.rs index 6a656a36..260c1a70 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,7 +19,7 @@ use serde_yaml; use serde::{self, de, Deserialize}; use serde::de::Error as SerdeError; use serde::de::{Visitor, MapAccess, Unexpected}; -use notify::{Watcher as WatcherApi, RecommendedWatcher as FileWatcher, op}; +use notify::{Watcher, watcher, DebouncedEvent, RecursiveMode}; use glutin::ModifiersState; @@ -1474,34 +1474,20 @@ impl Monitor { Monitor { _thread: ::util::thread::spawn_named("config watcher", move || { let (tx, rx) = mpsc::channel(); - let mut watcher = FileWatcher::new(tx).unwrap(); + let mut watcher = watcher(tx, Duration::from_millis(500)).unwrap(); let config_path = ::std::fs::canonicalize(path) .expect("canonicalize config path"); - watcher.watch(&config_path).expect("watch alacritty yml"); + watcher.watch(&config_path, RecursiveMode::NonRecursive).expect("watch alacritty yml"); loop { let event = rx.recv().expect("watcher event"); - let ::notify::Event { path, op } = event; - if let Ok(op) = op { - // Skip events that are just a rename - if op.contains(op::RENAME) && !op.contains(op::WRITE) { - continue; - } - - // Need to handle ignore for linux - if op.contains(op::IGNORED) { - if let Some(path) = path.as_ref() { - if let Err(err) = watcher.watch(&path) { - err_println!("failed to establish watch on {:?}: {:?}", - path, err); - } - } - } - - // Reload file - path.map(|path| { + match event { + DebouncedEvent::Rename(_, _) => continue, + DebouncedEvent::Write(path) | DebouncedEvent::Create(path) + | DebouncedEvent::Chmod(path) => { + // Reload file if path == config_path { match Config::load_from(path) { Ok(config) => { @@ -1510,8 +1496,9 @@ impl Monitor { }, Err(err) => err_println!("Ignoring invalid config: {}", err), } - } - }); + } + } + _ => {} } } }), |