feat(config): backup v1 file before v2 migration
- Add timestamped backup at `~/.cc-switch/config.v1.backup.<ts>.json` - Keep provider files untouched; only cc-switch metadata is backed up - Remove UI notification plan; backup only as requested - Update CHANGELOG with migration backup notes
This commit is contained in:
@@ -44,6 +44,11 @@ For users upgrading from v2.x (Electron version):
|
|||||||
- The app will automatically migrate your existing provider configurations
|
- The app will automatically migrate your existing provider configurations
|
||||||
- Window position and size preferences have been reset to defaults
|
- 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.<timestamp>.json`
|
||||||
|
- This only concerns cc-switch's own metadata file; your actual provider files under `~/.claude/` and `~/.codex/` are untouched.
|
||||||
|
|
||||||
### 🛠️ Development
|
### 🛠️ Development
|
||||||
- Added `pnpm typecheck` command for TypeScript validation
|
- Added `pnpm typecheck` command for TypeScript validation
|
||||||
- Added `pnpm format` and `pnpm format:check` for code formatting
|
- Added `pnpm format` and `pnpm format:check` for code formatting
|
||||||
@@ -64,4 +69,4 @@ For users upgrading from v2.x (Electron version):
|
|||||||
### Features
|
### Features
|
||||||
- Basic provider management
|
- Basic provider management
|
||||||
- Claude Code integration
|
- Claude Code integration
|
||||||
- Configuration file handling
|
- Configuration file handling
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
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;
|
use crate::provider::ProviderManager;
|
||||||
|
|
||||||
/// 应用类型
|
/// 应用类型
|
||||||
@@ -78,6 +78,23 @@ impl MultiAppConfig {
|
|||||||
|
|
||||||
let config = Self { version: 2, apps };
|
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()?;
|
config.save()?;
|
||||||
return Ok(config);
|
return Ok(config);
|
||||||
|
|||||||
@@ -167,6 +167,8 @@ export const tauriAPI = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// (保留空位,取消迁移提示)
|
||||||
|
|
||||||
// 选择配置文件(Tauri 暂不实现,保留接口兼容性)
|
// 选择配置文件(Tauri 暂不实现,保留接口兼容性)
|
||||||
selectConfigFile: async (): Promise<string | null> => {
|
selectConfigFile: async (): Promise<string | null> => {
|
||||||
console.warn("selectConfigFile 在 Tauri 版本中暂不支持");
|
console.warn("selectConfigFile 在 Tauri 版本中暂不支持");
|
||||||
|
|||||||
Reference in New Issue
Block a user