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: patch env not work on windows

Louisf1a2df4679ae
diff --git a/src-tauri/src/core/system/commands.rs b/src-tauri/src/core/system/commands.rs
index d99b1fdc0..172d293ae 100644
--- a/src-tauri/src/core/system/commands.rs
+++ b/src-tauri/src/core/system/commands.rs
@@ -317,36 +317,21 @@ pub fn launch_claude_code_with_config(
}
}
} else {
- // On Windows, write to a batch file
- let env_export: String = env_vars
- .iter()
- .map(|(k, v)| format!("set \"{}={}\"", k, v))
- .collect();
-
- let batch_content = format!(
- r#"@echo off
-REM Jan Local API Server - Claude Code Config
-{}
-
-echo Run: claude
-pause
-"#,
- env_export
- );
-
- let batch_file = "C:\\Users\\Public\\claude_code_env.bat";
- std::fs::write(batch_file, &batch_content).map_err(|e| e.to_string())?;
-
- std::process::Command::new("cmd")
- .arg("/c")
- .arg("start")
- .arg("Claude Code")
- .arg("/K")
- .arg(format!("{} && claude", env_export))
- .spawn()
- .map_err(|e| e.to_string())?;
+ // On Windows, set persistent user environment variables using setx
+ for (key, value) in &env_vars {
+ let output = std::process::Command::new("setx")
+ .arg(key)
+ .arg(value)
+ .output()
+ .map_err(|e| e.to_string())?;
+
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ return Err(format!("Failed to set env var {}: {}", key, stderr));
+ }
+ }
- log::info!("Env vars exported. Claude Code should now use them.");
+ log::info!("Environment variables set permanently in Windows registry.");
return Ok(());
}
}