use std::path::{Path, PathBuf};
use std::sync::Mutex;
type Hook = Box<dyn Fn() + Send + Sync>;
static INSTALLED: Mutex<Option<(PathBuf, Hook)>> = Mutex::new(None);
pub(crate) struct Installed;
impl Drop for Installed {
fn drop(&mut self) {
*INSTALLED.lock().expect("the save window is never poisoned") = None;
}
}
pub(crate) fn install(path: &Path, hook: impl Fn() + Send + Sync + 'static) -> Installed {
*INSTALLED.lock().expect("the save window is never poisoned") =
Some((path.to_path_buf(), Box::new(hook)));
Installed
}
pub(crate) fn pause(path: &Path) {
let installed = INSTALLED.lock().expect("the save window is never poisoned");
if let Some((wanted, hook)) = installed.as_ref() {
if wanted == path {
hook();
}
}
}