Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat: correctly kill openclaw process on Window per terminating app

Vanalite63dff625b54b
diff --git a/src-tauri/src/core/mcp/helpers.rs b/src-tauri/src/core/mcp/helpers.rs
index 41efea71c..938336386 100644
--- a/src-tauri/src/core/mcp/helpers.rs
+++ b/src-tauri/src/core/mcp/helpers.rs
@@ -768,7 +768,7 @@ async fn kill_process_by_pid(pid: u32) -> Result<(), String> {
use std::os::windows::process::CommandExt;
let mut cmd = Command::new("taskkill");
- cmd.args(&["/F", "/PID", &pid.to_string()]);
+ cmd.args(&["/F", "/T", "/PID", &pid.to_string()]);
#[cfg(windows)]
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rs
index 02be28748..c850d42ba 100644
--- a/src-tauri/src/core/openclaw/sandbox_direct.rs
+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs
@@ -120,7 +120,22 @@ impl Sandbox for DirectProcessSandbox {
async fn stop(&self, handle: &mut SandboxHandle) -> Result<(), String> {
if let SandboxHandle::Process(child) = handle {
- let _ = child.kill().await;
+ #[cfg(target_os = "windows")]
+ {
+ if let Some(pid) = child.id() {
+ use std::os::windows::process::CommandExt;
+ let mut cmd = tokio::process::Command::new("taskkill");
+ cmd.args(["/F", "/T", "/PID", &pid.to_string()]);
+ cmd.creation_flags(0x08000000);
+ let _ = cmd.output().await;
+ } else {
+ let _ = child.kill().await;
+ }
+ }
+ #[cfg(not(target_os = "windows"))]
+ {
+ let _ = child.kill().await;
+ }
return Ok(());
}
@@ -147,7 +162,7 @@ impl Sandbox for DirectProcessSandbox {
use std::os::windows::process::CommandExt;
let kill = |im: &'static str| async move {
let mut cmd = tokio::process::Command::new("taskkill");
- cmd.args(["/F", "/IM", im]);
+ cmd.args(["/F", "/T", "/IM", im]);
cmd.creation_flags(0x08000000);
let _ = cmd.output().await;
};
@@ -181,7 +196,7 @@ impl Sandbox for DirectProcessSandbox {
{
use std::os::windows::process::CommandExt;
let mut cmd = tokio::process::Command::new("cmd");
- cmd.args(["/C", &format!("for /f \"tokens=5\" %a in ('netstat -aon ^| findstr :{} ^| findstr LISTENING') do taskkill /F /PID %a", super::OPENCLAW_PORT)]);
+ cmd.args(["/C", &format!("for /f \"tokens=5\" %%a in ('netstat -aon ^| findstr :{} ^| findstr LISTENING') do taskkill /F /T /PID %%a", super::OPENCLAW_PORT)]);
cmd.creation_flags(0x08000000);
let _ = cmd.output().await;
}