mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-18 00:11:08 +08:00
* refactor(signal): migrate signal to handling async in windows and remove signal-hook dependency * refactor(signal): enhance Windows signal handling with improved cleanup logic * refactor(signal): improve exit handling in run function for async compatibility
36 lines
762 B
Rust
36 lines
762 B
Rust
use std::sync::OnceLock;
|
|
|
|
use clash_verge_logging::{Type, logging};
|
|
|
|
#[cfg(unix)]
|
|
mod unix;
|
|
#[cfg(windows)]
|
|
mod windows;
|
|
|
|
pub(crate) static RUNTIME: OnceLock<Option<tokio::runtime::Runtime>> = OnceLock::new();
|
|
|
|
pub fn register<F, Fut>(f: F)
|
|
where
|
|
F: Fn() -> Fut + Send + Sync + 'static,
|
|
Fut: Future + Send + 'static,
|
|
{
|
|
RUNTIME.get_or_init(|| match tokio::runtime::Runtime::new() {
|
|
Ok(rt) => Some(rt),
|
|
Err(e) => {
|
|
logging!(
|
|
info,
|
|
Type::SystemSignal,
|
|
"register shutdown signal failed, create tokio runtime error: {}",
|
|
e
|
|
);
|
|
None
|
|
}
|
|
});
|
|
|
|
#[cfg(unix)]
|
|
unix::register(f);
|
|
|
|
#[cfg(windows)]
|
|
windows::register(f);
|
|
}
|