romm_api/core/download/
job.rs1use std::sync::atomic::{AtomicUsize, Ordering};
4
5#[derive(Debug, Clone)]
7pub enum DownloadStatus {
8 Downloading,
9 Done,
10 SkippedAlreadyExists,
11 Cancelled,
12 FinalizeFailed(String),
13 Error(String),
14}
15
16#[derive(Debug, Clone)]
18pub struct DownloadJob {
19 pub id: usize,
20 pub rom_id: u64,
21 pub name: String,
22 pub platform: String,
23 pub progress: f64,
25 pub status: DownloadStatus,
26}
27
28static NEXT_JOB_ID: AtomicUsize = AtomicUsize::new(0);
29
30impl DownloadJob {
31 pub fn new(rom_id: u64, name: String, platform: String) -> Self {
33 Self {
34 id: NEXT_JOB_ID.fetch_add(1, Ordering::Relaxed),
35 rom_id,
36 name,
37 platform,
38 progress: 0.0,
39 status: DownloadStatus::Downloading,
40 }
41 }
42
43 pub fn percent(&self) -> u16 {
45 (self.progress * 100.0).round().min(100.0) as u16
46 }
47}