lighty_launch/installer/config.rs
1// Copyright (c) 2025 Hamadi
2// Licensed under the MIT License
3
4//! Configuration for the installer module
5
6use once_cell::sync::OnceCell;
7
8/// Configuration pour le téléchargement de fichiers
9#[derive(Debug, Clone, Copy)]
10pub struct DownloaderConfig {
11 /// Nombre maximum de téléchargements concurrents (défaut: 50)
12 pub max_concurrent_downloads: usize,
13 /// Nombre maximum de tentatives en cas d'échec (défaut: 3)
14 pub max_retries: u32,
15 /// Délai initial en millisecondes avant retry (défaut: 20ms, augmente exponentiellement)
16 pub initial_delay_ms: u64,
17}
18
19impl Default for DownloaderConfig {
20 fn default() -> Self {
21 Self {
22 max_concurrent_downloads: 50,
23 max_retries: 3,
24 initial_delay_ms: 20,
25 }
26 }
27}
28
29/// Configuration globale du downloader
30static DOWNLOADER_CONFIG: OnceCell<DownloaderConfig> = OnceCell::new();
31
32/// Initialise la configuration du downloader (à appeler une seule fois au démarrage)
33///
34/// # Example
35///
36/// ```no_run
37/// use lighty_launch::installer::config::{DownloaderConfig, init_downloader_config};
38///
39/// init_downloader_config(DownloaderConfig {
40/// max_concurrent_downloads: 100,
41/// max_retries: 5,
42/// initial_delay_ms: 50,
43/// });
44/// ```
45pub fn init_downloader_config(config: DownloaderConfig) {
46 DOWNLOADER_CONFIG.set(config).ok();
47}
48
49/// Récupère la configuration actuelle du downloader
50pub(crate) fn get_config() -> DownloaderConfig {
51 *DOWNLOADER_CONFIG.get_or_init(DownloaderConfig::default)
52}