2023-01-17 04:24:48 +11:00
|
|
|
use std::{path::Path, time::Duration};
|
|
|
|
|
|
|
|
use notify_debouncer_mini::{new_debouncer, notify::*, DebounceEventResult};
|
|
|
|
|
|
|
|
pub(crate) fn hot_reload(mut f: impl FnMut() -> Option<()> + Send + 'static) -> impl Sized {
|
|
|
|
let mut debouncer = new_debouncer(
|
|
|
|
Duration::from_millis(500),
|
|
|
|
None,
|
|
|
|
move |res: DebounceEventResult| match res {
|
|
|
|
Ok(_) => f().unwrap(),
|
|
|
|
Err(errors) => errors.iter().for_each(|e| println!("Error {:?}", e)),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
debouncer
|
|
|
|
.watcher()
|
|
|
|
.watch(
|
2023-02-03 21:22:39 +11:00
|
|
|
&Path::new(env!("CARGO_MANIFEST_DIR"))
|
2023-01-17 04:24:48 +11:00
|
|
|
.join("../../shader")
|
|
|
|
.canonicalize()
|
2023-02-03 21:22:39 +11:00
|
|
|
.unwrap(),
|
2023-01-17 04:24:48 +11:00
|
|
|
// We currently don't support hot reloading the imports, so don't recurse into there
|
|
|
|
RecursiveMode::NonRecursive,
|
|
|
|
)
|
|
|
|
.expect("Could watch shaders directory");
|
|
|
|
debouncer
|
|
|
|
}
|