Update lib.rs

This commit is contained in:
ForgQi committed 2025-07-22 02:17:08 +08:00
1 parent bd69b76124
commit 2c923cc8da
1 file changed
+44 -44
+44 -44
View File
@@ -104,53 +104,53 @@ fn shutdown_sidecar(app_handle: &tauri::AppHandle) -> Result<String, String> {
.lock() .lock()
.map_err(|_| "[tauri] Failed to acquire lock on sidecar process.")?; .map_err(|_| "[tauri] Failed to acquire lock on sidecar process.")?;
let shell = app_handle.shell(); let shell = app_handle.shell();
// let kill_command;
if let Some(mut process) = child_process.take() { if let Some(mut process) = child_process.take() {
let pid = process.pid(); let pid = process.pid();
process.kill().map_err(|e1| e1.to_string())?; // process.kill().map_err(|e1| e1.to_string())?;
println!("[tauri] Killing sidecar. Pid: {}", pid); println!("[tauri] Killing sidecar. Pid: {}", pid);
// #[cfg(target_os = "windows")] let kill_command;
// { #[cfg(target_os = "windows")]
// // taskkill /F (强制) /T (杀死进程树) /PID <pid> {
// // 这是在 Windows 上杀死进程及其所有子进程的最佳方式 // taskkill /F (强制) /T (杀死进程树) /PID <pid>
// println!("Using 'taskkill' on Windows to force kill process tree."); // 这是在 Windows 上杀死进程及其所有子进程的最佳方式
// kill_command = shell println!("Using 'taskkill' on Windows to force kill process tree.");
// .command("taskkill") kill_command = shell
// .args(&["/F", "/T", "/PID", &pid.to_string()]) .command("taskkill")
// .spawn(); .args(&["/F", "/T", "/PID", &pid.to_string()])
// } .spawn();
// match kill_command { }
// Ok((mut rx, _)) => { match kill_command {
// tauri::async_runtime::block_on(async move { Ok((mut rx, _)) => {
// let encoding = Encoding::for_label("GBK".as_ref()).unwrap(); tauri::async_runtime::block_on(async move {
// while let Some(event) = rx.recv().await { let encoding = Encoding::for_label("GBK".as_ref()).unwrap();
// match event { while let Some(event) = rx.recv().await {
// CommandEvent::Stdout(line) => println!( match event {
// "Force kill stdout: {:?}", CommandEvent::Stdout(line) => println!(
// encoding.decode_with_bom_removal(&line).0 "Force kill stdout: {:?}",
// ), encoding.decode_with_bom_removal(&line).0
// CommandEvent::Stderr(line) => eprintln!( ),
// "Force kill stderr: {:?}", CommandEvent::Stderr(line) => eprintln!(
// encoding.decode_with_bom_removal(&line).0 "Force kill stderr: {:?}",
// ), encoding.decode_with_bom_removal(&line).0
// CommandEvent::Terminated(payload) => { ),
// if payload.code == Some(0) { CommandEvent::Terminated(payload) => {
// println!("Sidecar (PID: {}) and its children force killed successfully.", pid); if payload.code == Some(0) {
// } else { println!("Sidecar (PID: {}) and its children force killed successfully.", pid);
// // 在 Windows 上,如果进程已不存在,taskkill 会返回非0代码(如128),这是正常的。 } else {
// // 在 Linux/macOS 上,如果进程已不存在,kill/pkill 会报错,也是正常的。 // 在 Windows 上,如果进程已不存在,taskkill 会返回非0代码(如128),这是正常的。
// println!("Force kill command finished. Process was likely already dead."); // 在 Linux/macOS 上,如果进程已不存在,kill/pkill 会报错,也是正常的。
// } println!("Force kill command finished. Process was likely already dead.");
// } }
// _ => {} }
// } _ => {}
// } }
// }); }
// } });
// Err(e) => { }
// eprintln!("Failed to execute force kill command: {}", e); Err(e) => {
// } eprintln!("Failed to execute force kill command: {}", e);
// } }
}
println!("[tauri] Sent 'sidecar shutdown' command to sidecar."); println!("[tauri] Sent 'sidecar shutdown' command to sidecar.");
Ok("'sidecar shutdown' command sent.".to_string()) Ok("'sidecar shutdown' command sent.".to_string())