Skip to main content

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/// Tuning knobs for the parallel file downloader.
9#[derive(Debug, Clone, Copy)]
10pub struct DownloaderConfig {
11    pub max_concurrent_downloads: usize,
12    pub max_retries: u32,
13    pub initial_delay_ms: u64,
14}
15
16impl Default for DownloaderConfig {
17    fn default() -> Self {
18        Self {
19            max_concurrent_downloads: 50,
20            max_retries: 3,
21            initial_delay_ms: 20,
22        }
23    }
24}
25
26/// Global downloader configuration; populated once on startup.
27static DOWNLOADER_CONFIG: OnceCell<DownloaderConfig> = OnceCell::new();
28
29/// Installs the downloader configuration. Call this once at startup.
30///
31/// # Example
32///
33/// ```no_run
34/// use lighty_launch::installer::config::{DownloaderConfig, init_downloader_config};
35///
36/// init_downloader_config(DownloaderConfig {
37///     max_concurrent_downloads: 100,
38///     max_retries: 5,
39///     initial_delay_ms: 50,
40/// });
41/// ```
42pub fn init_downloader_config(config: DownloaderConfig) {
43    DOWNLOADER_CONFIG.set(config).ok();
44}
45
46/// Returns the active downloader configuration (defaults if uninitialized).
47pub(crate) fn get_config() -> DownloaderConfig {
48    *DOWNLOADER_CONFIG.get_or_init(DownloaderConfig::default)
49}