rush_sync_server/setup/
setup_toml.rs1use crate::core::prelude::*;
3use std::path::PathBuf;
4use tokio::fs;
5
6const DEFAULT_CONFIG: &str = r#"[general]
8max_messages = 1000
9typewriter_delay = 5
10input_max_length = 100
11max_history = 30
12poll_rate = 16
13log_level = "info"
14current_theme = "dark"
15
16[language]
17current = "en"
18
19# =====================================================
20# SERVER MANAGEMENT CONFIGURATION
21# =====================================================
22[server]
23port_range_start = 8080 # Starting port for auto-allocation
24port_range_end = 8180 # Maximum port for auto-allocation
25max_concurrent = 10 # Maximum simultaneous servers
26shutdown_timeout = 5 # Graceful shutdown timeout (seconds)
27startup_delay_ms = 500 # Delay after server creation (milliseconds)
28workers = 1 # Actix workers per server
29
30# =====================================================
31# LOGGING CONFIGURATION
32# =====================================================
33[logging]
34max_file_size_mb = 100 # Log rotation size (100MB per file)
35max_archive_files = 9 # Archive generations (9 backups)
36compress_archives = true # GZIP compression for archives
37log_requests = true # Enable request logging
38log_security_alerts = true # Enable security monitoring
39log_performance = true # Enable performance metrics
40
41# =====================================================
42# THEME DEFINITIONS
43# =====================================================
44[theme.dark]
45output_bg = "Black"
46output_text = "White"
47output_cursor = "PIPE"
48output_cursor_color = "White"
49input_bg = "White"
50input_text = "Black"
51input_cursor_prefix = "/// "
52input_cursor = "PIPE"
53input_cursor_color = "Black"
54
55[theme.light]
56output_bg = "White"
57output_text = "Black"
58output_cursor = "PIPE"
59output_cursor_color = "Black"
60input_bg = "Black"
61input_text = "White"
62input_cursor_prefix = "/// "
63input_cursor = "PIPE"
64input_cursor_color = "White"
65
66[theme.green]
67output_bg = "Black"
68output_text = "Green"
69output_cursor = "BLOCK"
70output_cursor_color = "Green"
71input_bg = "LightGreen"
72input_text = "Black"
73input_cursor_prefix = "$ "
74input_cursor = "BLOCK"
75input_cursor_color = "Black"
76
77[theme.blue]
78output_bg = "White"
79output_text = "LightBlue"
80output_cursor = "UNDERSCORE"
81output_cursor_color = "Blue"
82input_bg = "Blue"
83input_text = "White"
84input_cursor_prefix = "> "
85input_cursor = "UNDERSCORE"
86input_cursor_color = "White"
87"#;
88
89pub async fn ensure_config_exists() -> Result<PathBuf> {
90 let exe_path = std::env::current_exe().map_err(AppError::Io)?;
91 let base_dir = exe_path
92 .parent()
93 .ok_or_else(|| AppError::Validation(get_translation("system.config.dir_error", &[])))?;
94
95 let config_dir = base_dir.join(".rss");
96 if !config_dir.exists() {
97 fs::create_dir_all(&config_dir)
98 .await
99 .map_err(AppError::Io)?;
100 }
101
102 let config_path = config_dir.join("rush.toml");
103 if !config_path.exists() {
104 fs::write(&config_path, DEFAULT_CONFIG)
105 .await
106 .map_err(AppError::Io)?;
107
108 log::info!(
109 "{}",
110 get_translation(
111 "system.config.file_created",
112 &[&config_path.display().to_string()]
113 )
114 );
115 }
116
117 Ok(config_path)
118}
119
120pub fn get_config_paths() -> Vec<PathBuf> {
121 let mut paths = Vec::new();
122 if let Ok(exe_path) = std::env::current_exe() {
123 if let Some(base_dir) = exe_path.parent() {
124 paths.push(base_dir.join(".rss/rush.toml"));
125 paths.push(base_dir.join("rush.toml"));
126 paths.push(base_dir.join("config/rush.toml"));
127 }
128 }
129 #[cfg(debug_assertions)]
130 {
131 paths.push(PathBuf::from("rush.toml"));
132 paths.push(PathBuf::from("src/rush.toml"));
133 }
134 paths
135}