Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
feat: enhance Telegram download progress and completion structures with additional fields
Tonho46f48fe00ce9
diff --git a/src-tauri/src/commands/telegram.rs b/src-tauri/src/commands/telegram.rsindex 2b5dea5a..4feba335 100644--- a/src-tauri/src/commands/telegram.rs+++ b/src-tauri/src/commands/telegram.rs@@ -4,24 +4,27 @@ use tokio::sync::mpsc;use tokio_util::sync::CancellationToken;use crate::platforms::telegram::api::{self, TelegramChat, TelegramMediaItem};-use crate::platforms::telegram::auth::{self, VerifyError};+use crate::platforms::telegram::auth::{self, QrPollStatus, VerifyError};use crate::AppState;#[derive(Clone, Serialize)]-struct TelegramDownloadProgress {+struct GenericDownloadProgress {id: u64,- file_name: String,+ title: String,+ platform: String,percent: f64,}#[derive(Clone, Serialize)]-struct TelegramDownloadComplete {+struct GenericDownloadComplete {id: u64,- file_name: String,+ title: String,+ platform: String,success: bool,error: Option<String>,file_path: Option<String>,file_size_bytes: Option<u64>,+ file_count: Option<u32>,}#[derive(Clone, Serialize)]@@ -39,6 +42,43 @@ pub async fn telegram_check_session(.map_err(|e| e.to_string())}+#[derive(Clone, Serialize)]+pub struct QrStartResponse {+ pub svg: String,+ pub expires: i32,+}++#[tauri::command]+pub async fn telegram_qr_start(+ state: tauri::State<'_, AppState>,+) -> Result<QrStartResponse, String> {+ let result = auth::qr_login_start(&state.telegram_session)+ .await+ .map_err(|e| e.to_string())?;+ Ok(QrStartResponse {+ svg: result.qr_svg,+ expires: result.expires,+ })+}++#[tauri::command]+pub async fn telegram_qr_poll(+ state: tauri::State<'_, AppState>,+) -> Result<String, String> {+ match auth::qr_login_poll(&state.telegram_session).await {+ Ok(QrPollStatus::Waiting) => Ok("waiting".to_string()),+ Ok(QrPollStatus::Success { phone }) => Ok(format!("success:{}", phone)),+ Ok(QrPollStatus::PasswordRequired { hint }) => {+ if hint.is_empty() {+ Ok("password_required".to_string())+ } else {+ Ok(format!("password_required:{}", hint))+ }+ }+ Err(e) => Err(e.to_string()),+ }+}+#[tauri::command]pub async fn telegram_send_code(state: tauri::State<'_, AppState>,@@ -147,9 +187,10 @@ pub async fn telegram_download_media(tokio::spawn(async move {let output_path = std::path::PathBuf::from(&output_dir).join(&file_name_clone);- let _ = app.emit("generic-download-progress", &TelegramDownloadProgress {+ let _ = app.emit("generic-download-progress", &GenericDownloadProgress {id: download_id,- file_name: file_name_clone.clone(),+ title: file_name_clone.clone(),+ platform: "telegram".to_string(),percent: 0.0,});@@ -159,9 +200,10 @@ pub async fn telegram_download_media(let file_name_progress = file_name_clone.clone();let progress_forwarder = tokio::spawn(async move {while let Some(percent) = rx.recv().await {- let _ = app_progress.emit("generic-download-progress", &TelegramDownloadProgress {+ let _ = app_progress.emit("generic-download-progress", &GenericDownloadProgress {id: download_id,- file_name: file_name_progress.clone(),+ title: file_name_progress.clone(),+ platform: "telegram".to_string(),percent,});}@@ -189,23 +231,27 @@ pub async fn telegram_download_media(match result {Ok(size) => {- let _ = app.emit("generic-download-complete", &TelegramDownloadComplete {+ let _ = app.emit("generic-download-complete", &GenericDownloadComplete {id: download_id,- file_name: file_name_clone,+ title: file_name_clone,+ platform: "telegram".to_string(),success: true,error: None,file_path: Some(output_path.to_string_lossy().to_string()),file_size_bytes: Some(size),+ file_count: Some(1),});}Err(e) => {- let _ = app.emit("generic-download-complete", &TelegramDownloadComplete {+ let _ = app.emit("generic-download-complete", &GenericDownloadComplete {id: download_id,- file_name: file_name_clone,+ title: file_name_clone,+ platform: "telegram".to_string(),success: false,error: Some(e.to_string()),file_path: None,file_size_bytes: None,+ file_count: None,});}}