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    pub fn download_progress(
16        id: impl Into<String>,
17        downloaded: u64,
18        total: u64,
19        speed_bps: f64,
20        eta_seconds: f64,
21        percentage: f64,
22    ) -> Self {
23        let _ = (eta_seconds, percentage); // DownloadEvent::progress calculates these
24        Self::Download {
25            event: DownloadEvent::progress(id, downloaded, total, speed_bps),
26        }
27    }
28
29    /// Create a download completed event.
30    pub fn download_completed(id: impl Into<String>, message: Option<String>) -> Self {
31        Self::Download {
32            event: DownloadEvent::completed(id, message),
33        }
34    }
35
36    /// Create a download failed event.
37    pub fn download_failed(id: impl Into<String>, error: impl Into<String>) -> Self {
38        Self::Download {
39            event: DownloadEvent::failed(id, error),
40        }
41    }
42
43    /// Create a download cancelled event.
44    pub fn download_cancelled(id: impl Into<String>) -> Self {
45        Self::Download {
46            event: DownloadEvent::cancelled(id),
47        }
48    }
49}