mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-18 09:52:13 +08:00
* fix(windows): ensure sidecar process dies with the main app * chore: fix clippy lints * chore: fix TS2307 error on commit. chore: Undo the changes about package.json and pnpm-lock.yaml * Fix formatting errors caused by merging. 刚刚的合并让原本的函数少了个结尾括号 * fix(windows): close process handle after assigning sidecar to job object * fix(windows): sidecar Job Object 错误改为向上传播并补充测试 将 job 创建逻辑抽为返回 Result<OwnedHandle> 的独立函数,任一 Win32 调用失败时 终止已 spawn 的子进程并返回 Err,不再静默降级。句柄由裸 isize 改为 OwnedHandle, 借助 RAII 自动关闭。新增 Windows 单元测试,覆盖 KILL_ON_JOB_CLOSE 生命周期 及无效 PID 的失败路径。 --------- Co-authored-by: wonfen <96291150+wonfen@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,8 @@ use std::{
|
||||
use tauri_plugin_shell::process::CommandChild;
|
||||
|
||||
use crate::singleton;
|
||||
#[cfg(target_os = "windows")]
|
||||
use std::os::windows::io::OwnedHandle;
|
||||
|
||||
pub(crate) static CLASH_LOGGER: Lazy<Arc<AsyncLogger>> = Lazy::new(|| Arc::new(AsyncLogger::new()));
|
||||
|
||||
@@ -41,6 +43,8 @@ impl fmt::Display for RunningMode {
|
||||
pub struct CoreManager {
|
||||
state: ArcSwap<State>,
|
||||
last_update: ArcSwapOption<Instant>,
|
||||
#[cfg(target_os = "windows")]
|
||||
job_handle: ArcSwapOption<OwnedHandle>,
|
||||
config_update_in_progress: AtomicBool,
|
||||
// 串行化 start/stop/restart 和 sidecar→service 交接。
|
||||
// 锁序固定为 config_update_in_progress → lifecycle_lock。
|
||||
@@ -70,6 +74,8 @@ impl Default for CoreManager {
|
||||
Self {
|
||||
state: ArcSwap::new(Arc::new(State::default())),
|
||||
last_update: ArcSwapOption::new(None),
|
||||
#[cfg(target_os = "windows")]
|
||||
job_handle: ArcSwapOption::new(None),
|
||||
config_update_in_progress: AtomicBool::new(false),
|
||||
lifecycle_lock: tokio::sync::Mutex::new(()),
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -113,6 +119,17 @@ impl CoreManager {
|
||||
self.last_update.store(Some(Arc::new(time)));
|
||||
}
|
||||
|
||||
/// Replaces the Windows Job Object handle owned by the core manager
|
||||
///
|
||||
/// Passing `None` drops the current handle, which closes the Job Object
|
||||
/// and terminates its assigned processes due to `KILL_ON_JOB_CLOSE`.
|
||||
///
|
||||
/// This method is currently only used on Windows.
|
||||
#[cfg(target_os = "windows")]
|
||||
fn set_job_handle(&self, handle: Option<OwnedHandle>) {
|
||||
self.job_handle.store(handle.map(Arc::new));
|
||||
}
|
||||
|
||||
fn try_start_config_update(&self) -> bool {
|
||||
!self.config_update_in_progress.swap(true, Ordering::AcqRel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user