meowy-webring/src/watcher.rs

30 lines
580 B
Rust

use notify::{Result, Watcher};
use shared::directories;
use crate::sites::Names;
pub(crate) fn hot_reloading() {
let (tx, rx) = std::sync::mpsc::channel();
let names_path = directories::get_names_project_path().unwrap();
let mut watcher = notify::recommended_watcher(tx).unwrap();
watcher
.watch(&names_path, notify::RecursiveMode::NonRecursive)
.unwrap();
for res in rx {
watch(res);
}
}
fn watch(res: Result<notify::Event>) {
match res {
Ok(event) => {
if event.kind.is_modify() {
Names::set();
}
}
Err(err) => println!("Error: {}", err),
}
}