33 lines
672 B
Rust
33 lines
672 B
Rust
use notify::{
|
|
event::{DataChange, ModifyKind},
|
|
EventKind, Result, Watcher,
|
|
};
|
|
use shared::directories;
|
|
|
|
use crate::sites;
|
|
|
|
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 == EventKind::Modify(ModifyKind::Data(DataChange::Any)) {
|
|
sites::set_names();
|
|
}
|
|
}
|
|
Err(err) => println!("Error: {}", err),
|
|
}
|
|
}
|