Skip to main content

mangofetch_core/core/
traits.rs

1use crate::models::queue::QueueItemInfo;
2use std::sync::Arc;
3
4/// Reporter trait for download progress and events.
5/// Implementations can be Tauri-based (desktop app) or CLI-based (terminal output).
6pub trait DownloadReporter: Send + Sync + 'static {
7    /// Report download progress update
8    fn on_progress(&self, download_id: u64, progress: crate::core::events::QueueItemProgress);
9
10    /// Report download completion
11    fn on_complete(
12        &self,
13        download_id: u64,
14        file_path: Option<String>,
15        file_size_bytes: Option<u64>,
16    );
17
18    /// Report download error
19    fn on_error(&self, download_id: u64, error_message: String);
20
21    /// Report retry attempt
22    fn on_retry(&self, download_id: u64, attempt: u32, delay_ms: u64);
23
24    /// Report phase change (e.g., "Fetching Info", "Downloading", "Merging")
25    fn on_phase_change(&self, download_id: u64, phase: String);
26
27    /// Report media preview info (for URL previews)
28    fn on_media_preview(
29        &self,
30        url: String,
31        title: String,
32        author: String,
33        thumbnail_url: Option<String>,
34        duration_seconds: Option<f64>,
35    );
36
37    /// Report a full queue state update
38    fn on_queue_update(&self, state: Vec<QueueItemInfo>);
39
40    /// Report system-level progress (e.g., dependency updates)
41    fn on_system_progress(&self, title: &str, percent: f32, message: &str);
42}
43
44pub type SharedReporter = Arc<dyn DownloadReporter>;