diff options
| author | 2026-01-13 15:37:55 +0800 | |
|---|---|---|
| committer | 2026-01-13 15:37:55 +0800 | |
| commit | 6fbb5f19cab02f3a0f18cdeda3da02e717b69cd6 (patch) | |
| tree | bb84869afeb316e2510018e2ba33c651488f3e71 /src-tauri/src/core/downloader.rs | |
| parent | b7e7f8de3d2200ef34510cda3601a50f62af798d (diff) | |
| download | DropOut-6fbb5f19cab02f3a0f18cdeda3da02e717b69cd6.tar.gz DropOut-6fbb5f19cab02f3a0f18cdeda3da02e717b69cd6.zip | |
feat: add offline account management and version fetching functionality
Diffstat (limited to 'src-tauri/src/core/downloader.rs')
| -rw-r--r-- | src-tauri/src/core/downloader.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src-tauri/src/core/downloader.rs b/src-tauri/src/core/downloader.rs new file mode 100644 index 0000000..8d717be --- /dev/null +++ b/src-tauri/src/core/downloader.rs @@ -0,0 +1,51 @@ +use std::path::PathBuf; +use tokio::sync::mpsc; +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone)] +pub struct DownloadTask { + pub url: String, + pub path: PathBuf, + pub sha1: Option<String>, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum DownloadProgress { + Started(String), + Progress { file: String, downloaded: u64, total: u64 }, + Finished(String), + Error(String, String), +} + +pub struct Downloader { + sender: mpsc::Sender<DownloadProgress>, +} + +impl Downloader { + pub fn new(sender: mpsc::Sender<DownloadProgress>) -> Self { + Self { sender } + } + + pub async fn download(&self, tasks: Vec<DownloadTask>) { + // TODO: Implement parallel download with limits + // Use futures::stream::StreamExt::buffer_unordered + + for task in tasks { + if let Err(_) = self.sender.send(DownloadProgress::Started(task.url.clone())).await { + break; + } + + // Simulate download for now or implement basic + // Ensure directory exists + if let Some(parent) = task.path.parent() { + let _ = tokio::fs::create_dir_all(parent).await; + } + + // Real implementation would use reqwest here + + if let Err(_) = self.sender.send(DownloadProgress::Finished(task.url)).await { + break; + } + } + } +} |