use std::{process::Command, sync::OnceLock};
use tokio::sync::Notify;
use winapi::{
shared::minwindef::{BOOL, DWORD, FALSE, TRUE},
um::{consoleapi::SetConsoleCtrlHandler, wincon::CTRL_BREAK_EVENT},
};
static SIGNAL_NOTIFY: OnceLock<Notify> = OnceLock::new();
unsafe extern "system" fn console_handler(ctrl_type: DWORD) -> BOOL {
match ctrl_type {
CTRL_BREAK_EVENT => {
if let Some(notify) = SIGNAL_NOTIFY.get() {
notify.notify_one();
}
TRUE
}
_ => FALSE,
}
}
pub async fn wait_reload() {
let notify = SIGNAL_NOTIFY.get_or_init(|| {
unsafe {
SetConsoleCtrlHandler(Some(console_handler), TRUE);
}
Notify::new()
});
notify.notified().await;
}
pub fn setup_process_detachment(_command: &mut Command) {
}