|
|
@@ -1,5 +1,7 @@
|
|
|
use crate::utils::shell::{run_shell_hidden, spawn_process, CommandOptions};
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
+use std::fs;
|
|
|
+use std::path::PathBuf;
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
pub struct ClaudeCodeStatus {
|
|
|
@@ -135,3 +137,119 @@ pub async fn launch_claude_code() -> CommandResult {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+/// 获取 Claude Code 配置文件路径
|
|
|
+fn get_claude_config_path() -> Option<PathBuf> {
|
|
|
+ dirs::home_dir().map(|home| home.join(".claude").join("settings.json"))
|
|
|
+}
|
|
|
+
|
|
|
+/// 打开 Claude Code 配置文件
|
|
|
+#[tauri::command]
|
|
|
+pub async fn open_claude_code_config() -> CommandResult {
|
|
|
+ let config_path = match get_claude_config_path() {
|
|
|
+ Some(path) => path,
|
|
|
+ None => {
|
|
|
+ return CommandResult {
|
|
|
+ success: false,
|
|
|
+ error: Some("Cannot determine home directory".to_string()),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 确保 .claude 目录存在
|
|
|
+ if let Some(parent) = config_path.parent() {
|
|
|
+ if !parent.exists() {
|
|
|
+ if let Err(e) = fs::create_dir_all(parent) {
|
|
|
+ return CommandResult {
|
|
|
+ success: false,
|
|
|
+ error: Some(format!("Failed to create .claude directory: {}", e)),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果配置文件不存在,创建带有默认内容的配置文件
|
|
|
+ if !config_path.exists() {
|
|
|
+ let default_config = r#"{
|
|
|
+ "alwaysThinkingEnabled": true,
|
|
|
+ "env": {
|
|
|
+ "ANTHROPIC_AUTH_TOKEN": "你的Key",
|
|
|
+ "ANTHROPIC_BASE_URL": "https://xiaoheiai.tiantianyy.com",
|
|
|
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-opus-4-5-20251101",
|
|
|
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-5-20251101",
|
|
|
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-opus-4-5-20251101",
|
|
|
+ "ANTHROPIC_MODEL": "claude-opus-4-5-20251101"
|
|
|
+ },
|
|
|
+ "compression": {
|
|
|
+ "defaultLevel": "light"
|
|
|
+ }
|
|
|
+}"#;
|
|
|
+ if let Err(e) = fs::write(&config_path, default_config) {
|
|
|
+ return CommandResult {
|
|
|
+ success: false,
|
|
|
+ error: Some(format!("Failed to create config file: {}", e)),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用系统默认程序打开配置文件
|
|
|
+ #[cfg(target_os = "windows")]
|
|
|
+ {
|
|
|
+ let result = spawn_process(
|
|
|
+ "cmd",
|
|
|
+ &["/c", "start", "", config_path.to_str().unwrap_or("")],
|
|
|
+ CommandOptions::hidden(),
|
|
|
+ );
|
|
|
+
|
|
|
+ match result {
|
|
|
+ Ok(_) => CommandResult {
|
|
|
+ success: true,
|
|
|
+ error: None,
|
|
|
+ },
|
|
|
+ Err(e) => CommandResult {
|
|
|
+ success: false,
|
|
|
+ error: Some(e),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #[cfg(target_os = "macos")]
|
|
|
+ {
|
|
|
+ let result = spawn_process(
|
|
|
+ "open",
|
|
|
+ &[config_path.to_str().unwrap_or("")],
|
|
|
+ CommandOptions::hidden(),
|
|
|
+ );
|
|
|
+
|
|
|
+ match result {
|
|
|
+ Ok(_) => CommandResult {
|
|
|
+ success: true,
|
|
|
+ error: None,
|
|
|
+ },
|
|
|
+ Err(e) => CommandResult {
|
|
|
+ success: false,
|
|
|
+ error: Some(e),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #[cfg(target_os = "linux")]
|
|
|
+ {
|
|
|
+ let result = spawn_process(
|
|
|
+ "xdg-open",
|
|
|
+ &[config_path.to_str().unwrap_or("")],
|
|
|
+ CommandOptions::hidden(),
|
|
|
+ );
|
|
|
+
|
|
|
+ match result {
|
|
|
+ Ok(_) => CommandResult {
|
|
|
+ success: true,
|
|
|
+ error: None,
|
|
|
+ },
|
|
|
+ Err(e) => CommandResult {
|
|
|
+ success: false,
|
|
|
+ error: Some(e),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|