use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AppConfig { pub theme: String, pub download_dir: String, pub video_format: String, pub video_quality: String, pub audio_format: String, pub audio_quality: String, pub cookies_mode: String, pub cookies_browser: String, pub cookies_path: String, pub embed_subtitles: bool, pub subtitle_lang: String, pub embed_thumbnail: bool, pub add_metadata: bool, pub concurrent_fragments: u32, pub speed_limit: String, pub proxy: String, pub ignore_errors: bool, pub sponsorblock_remove: bool, pub sponsorblock_cats: String, #[serde(default = "default_true")] pub auto_update_on_startup: bool, } fn default_true() -> bool { true } impl Default for AppConfig { fn default() -> Self { let download_dir = directories::UserDirs::new() .and_then(|dirs| dirs.download_dir().map(|p| p.to_string_lossy().to_string())) .unwrap_or_else(|| "Downloads".to_string()); Self { theme: "dark".to_string(), download_dir, video_format: "mp4".to_string(), video_quality: "Best Quality (En İyi)".to_string(), audio_format: "mp3".to_string(), audio_quality: "Best Quality (En İyi)".to_string(), cookies_mode: "none".to_string(), cookies_browser: "chrome".to_string(), cookies_path: String::new(), embed_subtitles: false, subtitle_lang: "tr,en".to_string(), embed_thumbnail: true, add_metadata: true, concurrent_fragments: 4, speed_limit: String::new(), proxy: String::new(), ignore_errors: true, sponsorblock_remove: false, sponsorblock_cats: "sponsor,intro,outro,selfpromo,interaction".to_string(), auto_update_on_startup: true, } } } #[cfg(test)] mod tests { use super::*; #[test] fn test_default_config() { let cfg = AppConfig::default(); assert_eq!(cfg.theme, "dark"); assert_eq!(cfg.video_format, "mp4"); assert_eq!(cfg.audio_format, "mp3"); assert_eq!(cfg.concurrent_fragments, 4); assert!(cfg.embed_thumbnail); assert!(cfg.add_metadata); assert!(cfg.auto_update_on_startup); assert!(!cfg.download_dir.is_empty()); } #[test] fn test_config_json_roundtrip() { let cfg = AppConfig::default(); let json = serde_json::to_string(&cfg).expect("Serialization failed"); let deserialized: AppConfig = serde_json::from_str(&json).expect("Deserialization failed"); assert_eq!(cfg.theme, deserialized.theme); assert_eq!(cfg.concurrent_fragments, deserialized.concurrent_fragments); } }