feat: add notify
This commit is contained in:
26
__linux/notify/src/main.rs
Normal file
26
__linux/notify/src/main.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use std::env;
|
||||
use notify::{Watcher, RecursiveMode, RawEvent, raw_watcher};
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
fn main() {
|
||||
// Create a channel to receive the events.
|
||||
let (tx, rx) = channel();
|
||||
|
||||
// Create a watcher object, delivering raw events.
|
||||
// The notification back-end is selected based on the platform.
|
||||
let mut watcher = raw_watcher(tx).unwrap();
|
||||
|
||||
// Add a path to be watched. All files and directories at that path and
|
||||
// below will be monitored for changes.
|
||||
watcher.watch(env::var("HOME").unwrap(), RecursiveMode::Recursive).unwrap();
|
||||
|
||||
loop {
|
||||
match rx.recv() {
|
||||
Ok(RawEvent{path: Some(path), op: Ok(op), cookie}) => {
|
||||
println!("{:?} {:?} ({:?})", op, path, cookie)
|
||||
},
|
||||
Ok(event) => println!("broken event: {:?}", event),
|
||||
Err(e) => println!("watch error: {:?}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user