Skip to main content

romm_api/core/download/manager/
mod.rs

1//! Shared download job list and background task spawning.
2
3mod extras;
4mod rom;
5
6use std::sync::{Arc, Mutex};
7
8use super::extras_job::ExtrasJob;
9use super::job::DownloadJob;
10
11/// Owns the shared download list and spawns background download tasks.
12///
13/// Frontends only need an `Arc<Mutex<Vec<DownloadJob>>>` to inspect jobs.
14#[derive(Clone)]
15pub struct DownloadManager {
16    pub(super) jobs: Arc<Mutex<Vec<DownloadJob>>>,
17    pub(super) extras_jobs: Arc<Mutex<Vec<ExtrasJob>>>,
18}
19
20impl Default for DownloadManager {
21    fn default() -> Self {
22        Self::new()
23    }
24}
25
26impl DownloadManager {
27    pub fn new() -> Self {
28        Self {
29            jobs: Arc::new(Mutex::new(Vec::new())),
30            extras_jobs: Arc::new(Mutex::new(Vec::new())),
31        }
32    }
33
34    /// Shared handle for observers (TUI, GUI, tests) to inspect jobs.
35    pub fn shared(&self) -> Arc<Mutex<Vec<DownloadJob>>> {
36        self.jobs.clone()
37    }
38
39    /// Shared extras jobs (composite batches).
40    pub fn shared_extras(&self) -> Arc<Mutex<Vec<ExtrasJob>>> {
41        self.extras_jobs.clone()
42    }
43}