Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix: keep openclaw alive after restart
Louisc6f627c23534
diff --git a/src-tauri/src/core/openclaw/cli.rs b/src-tauri/src/core/openclaw/cli.rsindex c69ccd4f9..cc9156e92 100644--- a/src-tauri/src/core/openclaw/cli.rs+++ b/src-tauri/src/core/openclaw/cli.rs@@ -13,47 +13,61 @@ fn hide_window(cmd: &mut Command) {#[cfg(not(target_os = "windows"))]fn hide_window(_cmd: &mut Command) {}+/// Returns the BUN_INSTALL directory (`~/.jan/.bunx`), creating it if needed.+fn get_bunx_dir() -> Option<std::path::PathBuf> {+ let dir = dirs::home_dir()?.join(".jan").join(".bunx");+ if let Err(e) = std::fs::create_dir_all(&dir) {+ log::warn!("Failed to create BUN_INSTALL dir {:?}: {}", dir, e);+ }+ Some(dir)+}+/// Build a command for openclaw. On Unix, uses bun as explicit interpreter/// to bypass shebang resolution. On Windows, runs openclaw.exe directly.-fn build_openclaw_command(args: &[&str]) -> Command {- let _ = super::ensure_bun_node_shim();-- let openclaw_path = super::get_openclaw_bin_path().ok();- let use_installed_binary = openclaw_path- .as_ref()- .map(|p| p.exists())- .unwrap_or(false);- let bun_path = super::resolve_bundled_bun();- let use_bun_interpreter = !cfg!(target_os = "windows")- && use_installed_binary- && bun_path.is_some();-- if use_bun_interpreter {- let mut cmd = Command::new(bun_path.unwrap());- cmd.arg(openclaw_path.unwrap());- if let Some(new_path) = super::build_augmented_path() {- cmd.env("PATH", new_path);+fn build_openclaw_command(args: &[&str]) -> tokio::process::Command {+ let bunx_dir = get_bunx_dir();++ let installed_bin = bunx_dir.as_ref().map(|d| {+ if cfg!(target_os = "windows") {+ d.join("bin").join("openclaw.exe")+ } else {+ d.join("bin").join("openclaw")}- cmd.args(args);- hide_window(&mut cmd);- cmd- } else if use_installed_binary {- let mut cmd = Command::new(openclaw_path.unwrap());- if let Some(new_path) = super::build_augmented_path() {- cmd.env("PATH", new_path);- }- cmd.args(args);- hide_window(&mut cmd);- cmd+ });++ let mut cmd = if installed_bin.as_ref().map(|p| p.exists()).unwrap_or(false) {+ log::info!("Running openclaw from installed path: {:?}", installed_bin);+ tokio::process::Command::new(installed_bin.unwrap())+ } else if let Some(bun) = super::resolve_bundled_bun() {+ log::info!("openclaw not installed yet, falling back to bun x");+ let mut c = tokio::process::Command::new(bun);+ c.arg("x");+ c.arg("openclaw");+ c} else {- let mut cmd = Command::new("openclaw");- if let Some(new_path) = super::build_augmented_path() {- cmd.env("PATH", new_path);- }- cmd.args(args);- hide_window(&mut cmd);- cmd+ tokio::process::Command::new("openclaw")+ };++ cmd.args(args)+ // .current_dir(config_dir)+ .stdout(Stdio::piped())+ .stderr(Stdio::piped());++ if let Some(dir) = bunx_dir {+ cmd.env("BUN_INSTALL", dir);}++ if let Some(new_path) = super::build_augmented_path() {+ cmd.env("PATH", new_path);+ }++ #[cfg(target_os = "windows")]+ {+ use std::os::windows::process::CommandExt;+ cmd.creation_flags(0x08000000);+ }++ cmd}async fn check_openclaw_installed() -> Result<Option<String>, String> {diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rsindex f452eeaa9..5edcb4ad0 100644--- a/src-tauri/src/core/openclaw/sandbox_direct.rs+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs@@ -122,8 +122,7 @@ impl Sandbox for DirectProcessSandbox {log::warn!("openclaw global install failed, will attempt to run anyway: {}", e);}- let mut cmd =- build_openclaw_command(&["gateway", "run", "--force"], &config.config_dir);+ let mut cmd = build_openclaw_command(&["gateway", "start"], &config.config_dir);for (key, value) in &config.env_vars {cmd.env(key, value);}