2023-01-17 04:24:48 +11:00
|
|
|
use std::{path::Path, time::Duration};
|
|
|
|
|
2023-03-05 22:33:30 +11:00
|
|
|
use anyhow::Result;
|
2023-01-17 04:24:48 +11:00
|
|
|
use notify_debouncer_mini::{new_debouncer, notify::*, DebounceEventResult};
|
|
|
|
|
2023-03-05 22:33:30 +11:00
|
|
|
pub(crate) fn hot_reload(mut f: impl FnMut() -> Option<()> + Send + 'static) -> Result<impl Sized> {
|
2023-01-17 04:24:48 +11:00
|
|
|
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)),
|
|
|
|
},
|
2023-03-05 22:33:30 +11:00
|
|
|
)?;
|
2023-01-17 04:24:48 +11:00
|
|
|
|
2023-03-05 22:33:30 +11:00
|
|
|
debouncer.watcher().watch(
|
|
|
|
&Path::new(env!("CARGO_MANIFEST_DIR"))
|
|
|
|
.join("../../shader")
|
|
|
|
.canonicalize()?,
|
|
|
|
// We currently don't support hot reloading the imports, so don't recurse into there
|
|
|
|
RecursiveMode::NonRecursive,
|
|
|
|
)?;
|
|
|
|
Ok(debouncer)
|
2023-01-17 04:24:48 +11:00
|
|
|
}
|