Update notify

This commit is contained in:
Jonathan Schleußer 2017-08-30 21:34:23 +02:00 committed by Joe Wilm
parent a3d35ec185
commit a7b50e0eb8
4 changed files with 31 additions and 53 deletions

16
Cargo.lock generated
View File

@ -17,7 +17,7 @@ dependencies = [
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-more 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"notify 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
@ -485,7 +485,7 @@ dependencies = [
[[package]]
name = "inotify"
version = "0.2.3"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
@ -723,19 +723,17 @@ dependencies = [
[[package]]
name = "notify"
version = "2.6.3"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"fsevent 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"inotify 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"inotify 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1374,7 +1372,7 @@ dependencies = [
"checksum gleam 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "bf887141f0c2a83eae026cbf3fba74f0a5cb0f01d20e5cdfcd8c4ad39295be1e"
"checksum glutin 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3cee1543cf7efce742534d31c024d8dd1aa0e8944d36ebdd7dfccdb80b84700d"
"checksum heapsize 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "556cd479866cf85c3f671209c85e8a6990211c916d1002c2fcb2e9b7cf60bc36"
"checksum inotify 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8458c07bdbdaf309c80e2c3304d14c3db64e7465d4f07cf589ccb83fd0ff31a"
"checksum inotify 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887fcc180136e77a85e6a6128579a719027b1bab9b1c38ea4444244fe262c20c"
"checksum iovec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "29d062ee61fccdf25be172e70f34c9f6efc597e1fb8f6526e8437b2046ab26be"
"checksum itertools 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22c285d60139cf413244894189ca52debcfd70b57966feed060da76802e415a0"
"checksum itoa 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ac17257442c2ed77dbc9fd555cf83c58b0c7f7d0e8f2ae08c0ac05c72842e1f6"
@ -1402,7 +1400,7 @@ dependencies = [
"checksum net2 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "3a80f842784ef6c9a958b68b7516bc7e35883c614004dd94959a4dca1b716c09"
"checksum nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79"
"checksum nodrop 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "52cd74cd09beba596430cc6e3091b74007169a56246e1262f0ba451ea95117b2"
"checksum notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e0e7eec936337952c4228b023007528a33b2fa039d96c2e8f32d764221a9c07"
"checksum notify 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "298d4401ff2c6cebb7f8944c90288647c89ce59029d43b439444cf1067df55e1"
"checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0"
"checksum objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "877f30f37acef6749b1841cceab289707f211aecfc756553cd63976190e6cc2e"
"checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"

View File

@ -14,7 +14,7 @@ name = "alacritty"
[dependencies]
libc = "0.2.30"
cgmath = "0.15"
notify = "2.6"
notify = "4"
bitflags = "0.9.1"
font = { path = "./font" }
errno = "0.2.3"

View File

@ -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),
}
}
});
}
}
_ => {}
}
}
}),

View File

@ -19,6 +19,7 @@ use std::mem::size_of;
use std::path::{PathBuf};
use std::ptr;
use std::sync::mpsc;
use std::time::Duration;
use cgmath;
use fnv::FnvHasher;
@ -26,7 +27,7 @@ use font::{self, Rasterizer, Rasterize, RasterizedGlyph, FontDesc, GlyphKey, Fon
use gl::types::*;
use gl;
use index::{Line, Column, RangeInclusive};
use notify::{Watcher as WatcherApi, RecommendedWatcher as Watcher, op};
use notify::{Watcher, watcher, RecursiveMode, DebouncedEvent};
use config::{self, Config, Delta};
use term::{self, cell, RenderableCell};
@ -536,29 +537,21 @@ impl QuadRenderer {
if cfg!(feature = "live-shader-reload") {
::std::thread::spawn(move || {
let (tx, rx) = ::std::sync::mpsc::channel();
let mut watcher = Watcher::new(tx).expect("create file watcher");
watcher.watch(TEXT_SHADER_F_PATH).expect("watch fragment shader");
watcher.watch(TEXT_SHADER_V_PATH).expect("watch vertex shader");
let mut watcher = watcher(tx, Duration::from_millis(500)).expect("create file watcher");
watcher.watch(TEXT_SHADER_F_PATH, RecursiveMode::NonRecursive)
.expect("watch fragment shader");
watcher.watch(TEXT_SHADER_V_PATH, RecursiveMode::NonRecursive)
.expect("watch vertex shader");
loop {
let event = rx.recv().expect("watcher event");
let ::notify::Event { path, op } = event;
if let Ok(op) = op {
if op.contains(op::RENAME) {
continue;
}
if op.contains(op::IGNORED) {
if let Some(path) = path.as_ref() {
if let Err(err) = watcher.watch(path) {
warn!("failed to establish watch on {:?}: {:?}", path, err);
}
}
msg_tx.send(Msg::ShaderReload)
.expect("msg send ok");
match event {
DebouncedEvent::Rename(_, _) => continue,
DebouncedEvent::Create(_) | DebouncedEvent::Write(_) | DebouncedEvent::Chmod(_) => {
msg_tx.send(Msg::ShaderReload).expect("msg send ok");
}
_ => {}
}
}
});