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.

fix: timeout on starting gateway on window & linux

Vanalite79a223609e8d
diff --git a/src-tauri/src/core/openclaw/mod.rs b/src-tauri/src/core/openclaw/mod.rs
index 5d8eed228..73ae597c3 100644
--- a/src-tauri/src/core/openclaw/mod.rs
+++ b/src-tauri/src/core/openclaw/mod.rs
@@ -123,8 +123,6 @@ pub fn resolve_bundled_bun() -> Option<std::path::PathBuf> {
None
}
-/// Create a `node` shim (symlink on Unix, copy on Windows) pointing to bundled Bun.
-/// Used as fallback for shebang resolution in service files.
pub fn ensure_bun_node_shim() -> Result<(), String> {
let bun_path = resolve_bundled_bun().ok_or("Bundled Bun not found")?;
let runtime_dir = get_openclaw_runtime_dir()?;
@@ -169,24 +167,27 @@ pub fn ensure_bun_node_shim() -> Result<(), String> {
#[cfg(target_os = "windows")]
{
- let needs_copy = if node_shim.exists() {
- let bun_modified = std::fs::metadata(&bun_path)
- .and_then(|m| m.modified())
- .ok();
- let shim_modified = std::fs::metadata(&node_shim)
- .and_then(|m| m.modified())
- .ok();
- match (bun_modified, shim_modified) {
- (Some(b), Some(s)) => b > s,
- _ => true,
- }
- } else {
- true
- };
+ let bun_modified = std::fs::metadata(&bun_path)
+ .and_then(|m| m.modified())
+ .ok();
+
+ for shim in &[node_shim, runtime_bin.join("bun.exe")] {
+ let needs_copy = if shim.exists() {
+ let shim_modified = std::fs::metadata(shim)
+ .and_then(|m| m.modified())
+ .ok();
+ match (bun_modified, shim_modified) {
+ (Some(b), Some(s)) => b > s,
+ _ => true,
+ }
+ } else {
+ true
+ };
- if needs_copy {
- std::fs::copy(&bun_path, &node_shim)
- .map_err(|e| format!("Failed to copy bun as node: {}", e))?;
+ if needs_copy {
+ std::fs::copy(&bun_path, shim)
+ .map_err(|e| format!("Failed to copy bun to {}: {}", shim.display(), e))?;
+ }
}
}
diff --git a/src-tauri/src/core/openclaw/sandbox_direct.rs b/src-tauri/src/core/openclaw/sandbox_direct.rs
index 086ec9105..e1057f85b 100644
--- a/src-tauri/src/core/openclaw/sandbox_direct.rs
+++ b/src-tauri/src/core/openclaw/sandbox_direct.rs
@@ -64,27 +64,30 @@ impl Sandbox for DirectProcessSandbox {
log::warn!("Failed to ensure node shim: {}", e);
}
- // On Windows, schtasks requires admin and may fail.
- let install_args = if super::resolve_bundled_bun().is_some() {
- vec!["gateway", "install", "--runtime", "bun"]
+ let use_child_process = if cfg!(target_os = "windows") {
+ true
} else {
- vec!["gateway", "install"]
- };
- let mut install_cmd = build_openclaw_command(&install_args.iter().map(|s| *s).collect::<Vec<_>>(), &config.config_dir);
- let service_installed = match install_cmd.output().await {
- Ok(output) if !output.status.success() => {
- let stderr = String::from_utf8_lossy(&output.stderr);
- log::error!("gateway install failed: {}", stderr.trim());
- false
- }
- Err(e) => {
- log::error!("Failed to run gateway install: {}", e);
- false
+ let install_args = if super::resolve_bundled_bun().is_some() {
+ vec!["gateway", "install", "--runtime", "bun"]
+ } else {
+ vec!["gateway", "install"]
+ };
+ let mut install_cmd = build_openclaw_command(&install_args.iter().map(|s| *s).collect::<Vec<_>>(), &config.config_dir);
+ match install_cmd.output().await {
+ Ok(output) if output.status.success() => false,
+ Ok(output) => {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ log::error!("gateway install failed: {}", stderr.trim());
+ true
+ }
+ Err(e) => {
+ log::error!("Failed to run gateway install: {}", e);
+ true
+ }
}
- _ => true,
};
- if service_installed {
+ if !use_child_process {
let mut cmd = build_openclaw_command(&["gateway", "start"], &config.config_dir);
for (key, value) in &config.env_vars {
cmd.env(key, value);
@@ -102,9 +105,14 @@ impl Sandbox for DirectProcessSandbox {
Ok(SandboxHandle::Named("direct-process".to_string()))
} else {
- log::info!("Service install unavailable, starting gateway as child process");
+ log::info!("Starting gateway as child process");
let mut cmd = build_openclaw_command(&["gateway"], &config.config_dir);
- cmd.stdout(Stdio::null()).stderr(Stdio::null());
+ cmd.stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
+ #[cfg(target_os = "windows")]
+ {
+ use std::os::windows::process::CommandExt;
+ cmd.creation_flags(0x00000008); // DETACHED_PROCESS
+ }
for (key, value) in &config.env_vars {
cmd.env(key, value);
}