rush_sync_server/setup/
setup_toml.rs

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