新增源配置文件管理

This commit is contained in:
2025-10-26 03:56:42 +08:00
parent d0973caf37
commit 6fd07b0bc0
4 changed files with 238 additions and 42 deletions

View File

@@ -738,6 +738,48 @@ pub async fn save_claude_settings(settings: serde_json::Value) -> Result<String,
Ok("Settings saved successfully".to_string())
}
/// Reads the Claude settings backup file
#[tauri::command]
pub async fn get_claude_settings_backup() -> Result<ClaudeSettings, String> {
log::info!("Reading Claude settings backup");
let claude_dir = get_claude_dir().map_err(|e| e.to_string())?;
let backup_path = claude_dir.join("settings.backup.json");
if !backup_path.exists() {
log::warn!("Settings backup file not found, returning empty settings");
return Ok(ClaudeSettings {
data: serde_json::json!({}),
});
}
let content = fs::read_to_string(&backup_path)
.map_err(|e| format!("Failed to read settings backup file: {}", e))?;
let data: serde_json::Value = serde_json::from_str(&content)
.map_err(|e| format!("Failed to parse settings backup JSON: {}", e))?;
Ok(ClaudeSettings { data })
}
/// Saves the Claude settings backup file
#[tauri::command]
pub async fn save_claude_settings_backup(settings: serde_json::Value) -> Result<String, String> {
log::info!("Saving Claude settings backup");
let claude_dir = get_claude_dir().map_err(|e| e.to_string())?;
let backup_path = claude_dir.join("settings.backup.json");
// Pretty print the JSON with 2-space indentation
let json_string = serde_json::to_string_pretty(&settings)
.map_err(|e| format!("Failed to serialize settings backup: {}", e))?;
fs::write(&backup_path, json_string)
.map_err(|e| format!("Failed to write settings backup file: {}", e))?;
Ok("Settings backup saved successfully".to_string())
}
/// Recursively finds all CLAUDE.md files in a project directory
#[tauri::command]
pub async fn find_claude_md_files(project_path: String) -> Result<Vec<ClaudeMdFile>, String> {

View File

@@ -24,11 +24,12 @@ use commands::claude::{
cancel_claude_execution, check_auto_checkpoint, check_claude_version, cleanup_old_checkpoints,
clear_checkpoint_manager, continue_claude_code, create_checkpoint, execute_claude_code,
find_claude_md_files, fork_from_checkpoint, get_checkpoint_diff, get_checkpoint_settings,
get_checkpoint_state_stats, get_claude_session_output, get_claude_settings, get_hooks_config,
get_project_sessions, get_recently_modified_files, get_session_timeline, get_system_prompt,
list_checkpoints, list_directory_contents, list_projects, list_running_claude_sessions,
load_session_history, open_new_session, read_claude_md_file, restore_checkpoint,
resume_claude_code, save_claude_md_file, save_claude_settings, save_system_prompt,
get_checkpoint_state_stats, get_claude_session_output, get_claude_settings,
get_claude_settings_backup, get_hooks_config, get_project_sessions,
get_recently_modified_files, get_session_timeline, get_system_prompt, list_checkpoints,
list_directory_contents, list_projects, list_running_claude_sessions, load_session_history,
open_new_session, read_claude_md_file, restore_checkpoint, resume_claude_code,
save_claude_md_file, save_claude_settings, save_claude_settings_backup, save_system_prompt,
search_files, track_checkpoint_message, track_session_messages,
unwatch_claude_project_directory, update_checkpoint_settings, update_hooks_config,
validate_hook_command, watch_claude_project_directory, ClaudeProcessState,
@@ -333,11 +334,13 @@ fn main() {
list_projects,
get_project_sessions,
get_claude_settings,
get_claude_settings_backup,
open_new_session,
get_system_prompt,
check_claude_version,
save_system_prompt,
save_claude_settings,
save_claude_settings_backup,
watch_claude_project_directory,
unwatch_claude_project_directory,
find_claude_md_files,