Files
clash-verge-rev-lite/src-tauri/src/module/signal/unix.rs
Tunglies 11035db307 feat: add signal handling for graceful shutdown on Windows and Unix (#5023)
* feat: add signal handling for graceful shutdown on Windows and Unix

Co-authored-by: oomeow <oomeow@outlook.com>

* chore: update Cargo.lock

* fix(windows): restore shutdown hook build by enabling missing Win32 APIs and removing stray tracing call

Includes the required windows-sys feature expansions and replaces a leftover tracing reference so the Windows shutdown hook builds successfully.

* fix: add deprecation warnings for encrypt_data and decrypt_data functions

---------

Co-authored-by: oomeow <oomeow@outlook.com>
Co-authored-by: Slinetrac <realakayuki@gmail.com>
2025-10-27 14:02:27 +08:00

37 lines
1.3 KiB
Rust

use signal_hook::{
consts::{SIGHUP, SIGINT, SIGTERM},
iterator::Signals,
low_level,
};
use crate::{feat, logging, logging_error, utils::logging::Type};
pub fn register() {
tauri::async_runtime::spawn(async {
let signals = [SIGTERM, SIGINT, SIGHUP];
match Signals::new(signals) {
Ok(mut sigs) => {
for signal in &mut sigs {
let signal_to_str = |signal: i32| match signal {
SIGTERM => "SIGTERM",
SIGINT => "SIGINT",
SIGHUP => "SIGHUP",
_ => "UNKNOWN",
};
logging!(info, Type::System, "捕获到信号 {}", signal_to_str(signal));
feat::clean_async().await;
// After printing it, do whatever the signal was supposed to do in the first place
logging_error!(
Type::System,
"信号 {:?} 默认处理失败",
low_level::emulate_default_handler(signal)
);
}
}
Err(e) => {
logging!(error, Type::System, "注册信号处理器失败: {}", e);
}
}
});
}