diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f30d0e..9896c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,11 @@ For users upgrading from v2.x (Electron version): - The app will automatically migrate your existing provider configurations - Window position and size preferences have been reset to defaults +#### Backup on v1→v2 Migration (cc-switch internal config) +- When the app detects an old v1 config structure at `~/.cc-switch/config.json`, it now creates a timestamped backup before writing the new v2 structure. +- Backup location: `~/.cc-switch/config.v1.backup..json` +- This only concerns cc-switch's own metadata file; your actual provider files under `~/.claude/` and `~/.codex/` are untouched. + ### 🛠️ Development - Added `pnpm typecheck` command for TypeScript validation - Added `pnpm format` and `pnpm format:check` for code formatting @@ -64,4 +69,4 @@ For users upgrading from v2.x (Electron version): ### Features - Basic provider management - Claude Code integration -- Configuration file handling \ No newline at end of file +- Configuration file handling diff --git a/src-tauri/src/app_config.rs b/src-tauri/src/app_config.rs index 5bdadd3..e60bbc3 100644 --- a/src-tauri/src/app_config.rs +++ b/src-tauri/src/app_config.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use crate::config::{get_app_config_path, write_json_file}; +use crate::config::{copy_file, get_app_config_dir, get_app_config_path, write_json_file}; use crate::provider::ProviderManager; /// 应用类型 @@ -78,6 +78,23 @@ impl MultiAppConfig { let config = Self { version: 2, apps }; + // 迁移前备份旧版(v1)配置文件 + let backup_dir = get_app_config_dir(); + let ts = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_secs(); + let backup_path = backup_dir.join(format!("config.v1.backup.{}.json", ts)); + + match copy_file(&config_path, &backup_path) { + Ok(()) => log::info!( + "已备份旧版配置文件: {} -> {}", + config_path.display(), + backup_path.display() + ), + Err(e) => log::warn!("备份旧版配置文件失败: {}", e), + } + // 保存迁移后的配置 config.save()?; return Ok(config); diff --git a/src/lib/tauri-api.ts b/src/lib/tauri-api.ts index 78858e5..71b53b2 100644 --- a/src/lib/tauri-api.ts +++ b/src/lib/tauri-api.ts @@ -167,6 +167,8 @@ export const tauriAPI = { } }, + // (保留空位,取消迁移提示) + // 选择配置文件(Tauri 暂不实现,保留接口兼容性) selectConfigFile: async (): Promise => { console.warn("selectConfigFile 在 Tauri 版本中暂不支持");