Skip to content

Commit 2678e0b

Browse files
committed
新增首次自动配置保存备份配置文件,优化续写逻辑。
1 parent 9610bb9 commit 2678e0b

File tree

9 files changed

+161
-36
lines changed

9 files changed

+161
-36
lines changed

README.md

Lines changed: 107 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
11
# 88code Desktop
22

3-
88code Claude Code 和 Codex 自动配置工具
3+
88code Claude Code 和 Codex 配置工具
44

55
## 功能特性
66

7-
### 1. Claude Code 自动配置
8-
- 用户输入 Base URL 和 API 密钥
7+
### 1. Claude Code 配置
8+
- **自动配置模式**: 快速配置 Base URL 和 API 密钥
9+
- **高级配置模式**: 自定义完整 JSON 配置内容
910
- 自动配置 `~/.claude/settings.json` 文件
11+
- 支持配置续写,保留现有配置字段
1012
- 跨平台支持(Windows/macOS/Linux)
1113

12-
### 2. Codex 自动配置
13-
- 用户输入 API 密钥
14+
### 2. Code 终端配置
15+
- 配置环境变量 `ANTHROPIC_BASE_URL``ANTHROPIC_AUTH_TOKEN`
16+
- Windows: 永久设置系统环境变量
17+
- Linux/macOS: 写入 shell 配置文件(.zshrc/.bashrc)
18+
- 支持清空配置功能
19+
20+
### 3. Codex 配置
21+
- **自动配置模式**: 快速配置 API 密钥和 Base URL
22+
- **高级配置模式**: 自定义 auth.json 和 config.toml 内容
1423
- 自动配置 `~/.codex/auth.json``config.toml`
24+
- 支持配置续写,保留现有配置字段
1525
- **永久设置环境变量 key88**
1626

27+
### 4. VSCode 扩展配置
28+
- **Claude 扩展**: 配置 `~/.claude/config.json`
29+
- **Codex (ChatGPT) 扩展**: 配置 VSCode settings.json
30+
- 自动检测 VSCode 安装路径(支持 Stable/Insiders/VSCodium)
31+
32+
### 🆕 5. 配置备份功能 (v1.1.0)
33+
- **首次配置自动备份**: 在修改配置前自动创建 .bak 备份文件
34+
- **智能备份保护**: 仅首次创建备份,已存在的 .bak 文件不会被覆盖
35+
- **全面覆盖**: 所有配置文件(Claude/Codex/VSCode/终端)均支持备份
36+
- **备份位置**:
37+
- `~/.claude/settings.json.bak`
38+
- `~/.claude/config.json.bak`
39+
- `~/.codex/auth.json.bak`
40+
- `~/.codex/config.toml.bak`
41+
- `[VSCode配置目录]/settings.json.bak`
42+
1743
## 技术栈
1844

1945
- **前端**: Vue 3.5.13 (Composition API) + Tailwind CSS 4
@@ -84,44 +110,94 @@ Codex 配置会自动设置环境变量 `key88=<您的API密钥>`
84110
## 注意事项
85111

86112
1. 首次配置会自动创建配置目录和文件
87-
2. 如果配置文件已存在,会合并现有配置(Claude Code)或覆盖(Codex)
88-
3. 配置使用原子写入机制,确保配置文件完整性
89-
4. API 密钥以密码形式输入,配置成功后会自动清空输入框
113+
2. **自动备份**: 首次配置前会自动创建 .bak 备份文件,保护原始配置
114+
3. **配置续写**: 配置文件已存在时,会智能合并现有配置,不会丢失其他字段
115+
4. 配置使用原子写入机制,确保配置文件完整性
116+
5. API 密钥以密码形式输入,配置成功后会自动清空输入框
117+
6. 高级配置支持 JSON/TOML 格式验证,确保配置正确性
90118

91119
## 项目结构
92120

93121
```
94122
88code-desktop/
95-
├── src/ # Vue 3 前端代码
96-
│ ├── components/ # Vue 组件
97-
│ │ ├── Sidebar.vue # 侧边栏导航
98-
│ │ ├── ClaudeConfigPanel.vue # Claude 配置面板
99-
│ │ ├── CodexConfigPanel.vue # Codex 配置面板
100-
│ │ └── Notification.vue # 通知组件
101-
│ ├── App.vue # 主应用
102-
│ ├── main.js # 入口文件
103-
│ ├── types.ts # TypeScript 类型定义
104-
│ └── index.css # 全局样式
105-
├── src-tauri/ # Rust 后端代码
106-
│ └── src/
107-
│ ├── config.rs # 配置路径管理和原子写入
108-
│ ├── claude_config.rs # Claude 配置逻辑
109-
│ ├── codex_config.rs # Codex 配置逻辑
110-
│ ├── env_manager.rs # 环境变量管理
111-
│ ├── commands.rs # Tauri 命令
112-
│ └── lib.rs # 主模块
113-
├── package.json # 前端依赖
114-
├── Cargo.toml # Rust 依赖
115-
└── README.md # 项目说明
123+
├── src/ # Vue 3 前端代码
124+
│ ├── components/ # Vue 组件
125+
│ │ ├── icons/ # 图标组件
126+
│ │ │ ├── ClaudeIcon.vue # Claude 图标
127+
│ │ │ ├── CodexIcon.vue # Codex 图标
128+
│ │ │ ├── VSCodeIcon.vue # VSCode 图标
129+
│ │ │ ├── JetBrainsIcon.vue # JetBrains 图标
130+
│ │ │ └── TerminalIcon.vue # 终端图标
131+
│ │ ├── Sidebar.vue # 侧边栏导航
132+
│ │ ├── TabButton.vue # 标签按钮组件
133+
│ │ ├── ClaudeConfigPanel.vue # Claude Code 配置面板
134+
│ │ ├── CodexConfigPanel.vue # Codex 配置面板
135+
│ │ ├── AdvancedConfigModal.vue # 高级配置模态框
136+
│ │ └── Notification.vue # 通知组件
137+
│ ├── assets/ # 静态资源
138+
│ │ └── vue.svg # Vue logo
139+
│ ├── App.vue # 主应用组件
140+
│ ├── main.js # Vue 应用入口
141+
│ ├── types.ts # TypeScript 类型定义
142+
│ └── index.css # Tailwind CSS 全局样式
143+
├── src-tauri/ # Rust 后端代码
144+
│ ├── src/
145+
│ │ ├── config.rs # 配置路径管理、原子写入、备份功能
146+
│ │ ├── claude_config.rs # Claude Code 配置逻辑
147+
│ │ ├── codex_config.rs # Codex 配置逻辑
148+
│ │ ├── vscode.rs # VSCode 扩展配置逻辑
149+
│ │ ├── env_manager.rs # 环境变量管理(终端配置)
150+
│ │ ├── commands.rs # Tauri 命令定义
151+
│ │ ├── lib.rs # 库主模块
152+
│ │ └── main.rs # 应用入口
153+
│ ├── icons/ # 应用图标资源
154+
│ ├── capabilities/ # Tauri 权限配置
155+
│ ├── Cargo.toml # Rust 依赖配置
156+
│ └── tauri.conf.json # Tauri 应用配置
157+
├── public/ # 静态资源
158+
│ ├── tauri.svg
159+
│ └── vite.svg
160+
├── package.json # Node.js 依赖配置
161+
├── vite.config.js # Vite 构建配置
162+
├── tailwind.config.js # Tailwind CSS 配置
163+
├── index.html # HTML 入口
164+
└── README.md # 项目文档
116165
```
117166

118167
## 许可证
119168

120169
MIT
121170

122-
## 版本
171+
## 版本历史
172+
173+
### v1.1.0 (2025-10-05)
174+
175+
176+
- 🆕 新增配置备份功能,首次配置自动创建 .bak 备份文件
177+
178+
- ✨ 智能备份保护,已存在的备份不会被覆盖
179+
180+
- 📦 全面支持所有配置文件的备份(Claude/Codex/VSCode/终端)
181+
182+
- 🔧 优化配置续写逻辑,确保不破坏原有配置
183+
184+
### v1.0.0 (2025-10-04)
185+
186+
- ✅ Claude Code 自动配置
187+
- ✅ Codex 自动配置
188+
- ✅ Code 终端环境变量配置
189+
- ✅ VSCode 扩展配置
190+
- ✅ 高级配置模式
191+
- ✅ 官方图标
192+
- ✅ 跨平台支持(Windows/macOS/Linux)
193+
194+
### v0.1.0 (2025-10-01)
123195

124-
1.0.0
196+
- ✅ Claude Code 自动配置
197+
- ✅ Codex 自动配置
198+
- ✅ Code 终端环境变量配置
199+
- ✅ VSCode 扩展配置
200+
- ✅ 跨平台支持(Windows/macOS/Linux)
125201

126202
---
127203

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "88code-desktop",
33
"private": true,
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"type": "module",
66
"description": "88code Claude Code & Codex 配置工具",
77
"scripts": {

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "code-desktop"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
description = "88code Claude Code & Codex 配置工具"
55
authors = ["88code"]
66
edition = "2021"

src-tauri/src/claude_config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ impl Default for ClaudeSettings {
3636
pub fn configure_claude_code(base_url: String, api_key: String) -> Result<(), String> {
3737
let settings_path = get_claude_settings_path();
3838

39+
// 首次配置前创建备份
40+
crate::config::create_backup_if_not_exists(&settings_path)?;
41+
3942
// 读取现有配置JSON并提取未知字段(使用Vec保持顺序)
4043
let mut extra_env = Vec::new();
4144
let mut extra_root = Vec::new();
@@ -135,6 +138,9 @@ pub fn get_claude_config() -> Result<ClaudeSettings, String> {
135138
pub fn configure_claude_advanced(config_content: String) -> Result<(), String> {
136139
let settings_path = get_claude_settings_path();
137140

141+
// 首次配置前创建备份
142+
crate::config::create_backup_if_not_exists(&settings_path)?;
143+
138144
// 验证JSON格式
139145
let new_config: Value = serde_json::from_str(&config_content)
140146
.map_err(|e| format!("配置内容格式错误: {}", e))?;

src-tauri/src/codex_config.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::{get_codex_auth_path, get_codex_config_path, write_json_file};
1+
use crate::config::{get_codex_auth_path, get_codex_config_path};
22
use serde::{Deserialize, Serialize};
33
use serde_json::Value;
44
use std::collections::HashMap;
@@ -41,6 +41,10 @@ pub fn configure_codex(base_url: String, api_key: String) -> Result<(), String>
4141
let auth_path = get_codex_auth_path();
4242
let config_path = get_codex_config_path();
4343

44+
// 首次配置前创建备份
45+
crate::config::create_backup_if_not_exists(&auth_path)?;
46+
crate::config::create_backup_if_not_exists(&config_path)?;
47+
4448
// 读取现有 auth.json,提取所有字段(使用Vec保持顺序)
4549
let mut extra_fields = Vec::new();
4650

@@ -216,6 +220,10 @@ pub fn configure_codex_advanced(
216220
let auth_path = get_codex_auth_path();
217221
let config_path = get_codex_config_path();
218222

223+
// 首次配置前创建备份
224+
crate::config::create_backup_if_not_exists(&auth_path)?;
225+
crate::config::create_backup_if_not_exists(&config_path)?;
226+
219227
// 验证并解析 auth.json
220228
let new_auth_value: Value = serde_json::from_str(&auth_json)
221229
.map_err(|e| format!("auth.json 格式错误: {}", e))?;

src-tauri/src/config.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,33 @@ pub fn get_config_paths_info() -> ConfigPaths {
142142
codex_config: get_codex_config_path().to_string_lossy().to_string(),
143143
}
144144
}
145+
146+
/// 创建备份文件(仅在.bak文件不存在时创建)
147+
/// 返回 Ok(true) 表示创建了备份, Ok(false) 表示备份已存在
148+
pub fn create_backup_if_not_exists(file_path: &Path) -> Result<bool, String> {
149+
// 如果原文件不存在,无需备份
150+
if !file_path.exists() {
151+
return Ok(false);
152+
}
153+
154+
// 生成备份文件路径
155+
let backup_path = file_path.with_extension(
156+
format!("{}.bak", file_path.extension()
157+
.and_then(|s| s.to_str())
158+
.unwrap_or("")
159+
).trim_start_matches('.')
160+
);
161+
162+
// 如果备份文件已存在,不再覆盖
163+
if backup_path.exists() {
164+
log::info!("备份文件已存在,跳过: {:?}", backup_path);
165+
return Ok(false);
166+
}
167+
168+
// 创建备份
169+
fs::copy(file_path, &backup_path)
170+
.map_err(|e| format!("创建备份文件失败: {}", e))?;
171+
172+
log::info!("首次备份成功: {:?} -> {:?}", file_path, backup_path);
173+
Ok(true)
174+
}

src-tauri/src/vscode.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ pub fn configure_vscode_claude(api_key: String, _base_url: String) -> Result<Str
226226
let config_dir = get_claude_config_dir();
227227
let config_path = config_dir.join("config.json");
228228

229+
// 首次配置前创建备份
230+
crate::config::create_backup_if_not_exists(&config_path)?;
231+
229232
// 3. 创建配置内容
230233
let config_content = json!({
231234
"primaryApiKey": api_key
@@ -245,6 +248,8 @@ pub fn configure_vscode_claude(api_key: String, _base_url: String) -> Result<Str
245248
pub fn configure_vscode_codex(base_url: String, api_key: String) -> Result<String, String> {
246249
// 查找或创建 settings.json 路径
247250
let settings_path = if let Some(path) = find_existing_settings() {
251+
// 首次配置前创建备份
252+
crate::config::create_backup_if_not_exists(&path)?;
248253
path
249254
} else {
250255
// 如果找不到现有配置,使用第一个候选路径(通常是 Code Stable)

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "code-desktop",
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"identifier": "com.88code.desktop",
66
"build": {
77
"beforeDevCommand": "pnpm dev",

0 commit comments

Comments
 (0)