use std::fs; use crate::models::AppConfig; use super::account::get_data_dir; const CONFIG_FILE: &str = "config.json"; /// Load application configuration pub fn load_app_config() -> Result { let data_dir = get_data_dir()?; let config_path = data_dir.join(CONFIG_FILE); if !config_path.exists() { return Ok(AppConfig::new()); } let content = fs::read_to_string(&config_path) .map_err(|e| format!("Failed to read config file: {}", e))?; serde_json::from_str(&content) .map_err(|e| format!("Failed to parse config file: {}", e)) } /// Save application configuration pub fn save_app_config(config: &AppConfig) -> Result<(), String> { let data_dir = get_data_dir()?; let config_path = data_dir.join(CONFIG_FILE); let content = serde_json::to_string_pretty(config) .map_err(|e| format!("Failed to serialize config: {}", e))?; fs::write(&config_path, content) .map_err(|e| format!("Failed to save config: {}", e)) }