rush_sync_server/setup/
setup_toml.rs

1// =====================================================
2// FILE: src/setup/setup_toml.rs - SICHERE DEFAULTS (KORRIGIERT)
3// =====================================================
4
5use crate::core::prelude::*;
6use std::path::PathBuf;
7use tokio::fs;
8
9// ✅ SICHERE DEFAULT-CONFIG mit Performance-Kommentaren + PROMPT SEKTION
10
11const DEFAULT_CONFIG: &str = r#"[general]
12max_messages = 100
13# Typewriter-Effekt: 50ms = 20 Zeichen/Sekunde (empfohlen: 30-100ms)
14typewriter_delay = 5
15input_max_length = 100
16max_history = 30
17# Poll-Rate: 16ms = 60 FPS (empfohlen: 16-33ms, NICHT unter 16!)
18poll_rate = 16
19log_level = "info"
20current_theme = "dark"
21
22[language]
23current = "en"
24
25[prompt]
26text = "/// "
27color = "Black"
28
29[theme.dark]
30input_text = "Black"
31input_bg = "White"
32cursor = "Black"
33output_text = "White"
34output_bg = "Black"
35
36[theme.light]
37input_text = "White"
38input_bg = "Black"
39cursor = "White"
40output_text = "Black"
41output_bg = "White"
42
43[theme.green]
44input_text = "Black"
45input_bg = "Green"
46cursor = "Black"
47output_text = "Green"
48output_bg = "Black"
49
50[theme.blue]
51input_text = "White"
52input_bg = "Blue"
53cursor = "White"
54output_text = "Blue"
55output_bg = "White"
56
57# =================================================================
58# PERFORMANCE-HINWEISE:
59# =================================================================
60# poll_rate:
61#   - 16ms = 60 FPS (EMPFOHLEN für flüssiges UI)
62#   - 33ms = 30 FPS (akzeptabel für langsamere Systeme)
63#   - 1-15ms = NICHT empfohlen (hohe CPU-Last!)
64#   - 0ms = CRASH! (Tokio interval panic)
65#
66# typewriter_delay:
67#   - 50ms = 20 Zeichen/Sekunde (gut lesbar)
68#   - 30ms = 33 Zeichen/Sekunde (schnell)
69#   - 100ms = 10 Zeichen/Sekunde (langsam)
70#   - 0ms = Typewriter-Effekt deaktiviert
71#
72# current_theme:
73#   - "dark" = Dunkles Theme (Standard)
74#   - "light" = Helles Theme
75#   - "matrix" = Matrix-Style (Grün)
76#   - "blue" = Blaues Theme
77# =================================================================
78"#;
79
80pub async fn ensure_config_exists() -> Result<PathBuf> {
81    let exe_path = std::env::current_exe().map_err(AppError::Io)?;
82    let base_dir = exe_path
83        .parent()
84        .ok_or_else(|| AppError::Validation(get_translation("system.config.dir_error", &[])))?;
85
86    let config_dir = base_dir.join(".rss");
87    if !config_dir.exists() {
88        fs::create_dir_all(&config_dir)
89            .await
90            .map_err(AppError::Io)?;
91        log::debug!(
92            "{}",
93            get_translation(
94                "system.config.dir_created",
95                &[&config_dir.display().to_string()]
96            )
97        );
98    }
99
100    let config_path = config_dir.join("rush.toml");
101    if !config_path.exists() {
102        fs::write(&config_path, DEFAULT_CONFIG)
103            .await
104            .map_err(AppError::Io)?;
105
106        // ✅ INFO NUR BEI FIRST-RUN
107        log::info!(
108            "{}",
109            get_translation(
110                "system.config.file_created",
111                &[&config_path.display().to_string()]
112            )
113        );
114
115        // ✅ PERFORMANCE-TIPP für neue Nutzer
116        log::info!("💡 Tipp: Für optimale Performance, behalte poll_rate >= 16ms");
117    }
118
119    Ok(config_path)
120}
121
122pub fn get_config_paths() -> Vec<PathBuf> {
123    let mut paths = Vec::new();
124    if let Ok(exe_path) = std::env::current_exe() {
125        if let Some(base_dir) = exe_path.parent() {
126            paths.push(base_dir.join(".rss/rush.toml"));
127            paths.push(base_dir.join("rush.toml"));
128            paths.push(base_dir.join("config/rush.toml"));
129        }
130    }
131    #[cfg(debug_assertions)]
132    {
133        paths.push(PathBuf::from("rush.toml"));
134        paths.push(PathBuf::from("src/rush.toml"));
135    }
136    paths
137}