Skip to main content

gglib_core/events/
download.rs

1//! Download progress and completion events.
2
3use super::AppEvent;
4use crate::download::DownloadEvent;
5
6impl AppEvent {
7    /// Create a download started event.
8    pub fn download_started(id: impl Into<String>, _display_name: impl Into<String>) -> Self {
9        Self::Download {
10            event: DownloadEvent::started(id),
11        }
12    }
13
14    /// Create a download progress event.
15    ///
16    /// `speed_bps` and `eta_seconds` come from the download manager's
17    /// `RateEstimator` and are `None` until it has warmed up; the percentage is
18    /// derived from the byte counts.
19    pub fn download_progress(
20        id: impl Into<String>,
21        downloaded: u64,
22        total: u64,
23        speed_bps: Option<f64>,
24        eta_seconds: Option<f64>,
25    ) -> Self {
26        Self::Download {
27            event: DownloadEvent::progress(id, downloaded, total, speed_bps, eta_seconds),
28        }
29    }
30
31    /// Create a download completed event.
32    pub fn download_completed(id: impl Into<String>, message: Option<String>) -> Self {
33        Self::Download {
34            event: DownloadEvent::completed(id, message),
35        }
36    }
37
38    /// Create a download failed event.
39    pub fn download_failed(id: impl Into<String>, error: impl Into<String>) -> Self {
40        Self::Download {
41            event: DownloadEvent::failed(id, error),
42        }
43    }
44
45    /// Create a download cancelled event.
46    pub fn download_cancelled(id: impl Into<String>) -> Self {
47        Self::Download {
48            event: DownloadEvent::cancelled(id),
49        }
50    }
51}