From 37e53c20df3decfe1aa56b7404ed73afb33b2545 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 10 Mar 2025 21:48:12 -0400 Subject: [PATCH] notify of download start --- .../src/threads/downloader_thread.rs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/desktop/src-tauri/src/threads/downloader_thread.rs b/crates/desktop/src-tauri/src/threads/downloader_thread.rs index f9d61b1b5c..490588820d 100644 --- a/crates/desktop/src-tauri/src/threads/downloader_thread.rs +++ b/crates/desktop/src-tauri/src/threads/downloader_thread.rs @@ -13,6 +13,7 @@ use tauri::{AppHandle, Emitter}; use tempfile::NamedTempFile; use tokio::task::JoinHandle; +const NOTIFICATION_CHANNEL_NAME : &str = "notification"; const MAX_FILES : usize = 8; const CHUNK_SIZE : usize = 1024 * 1024; const PARALLEL_FAILURES : usize = 8; @@ -28,12 +29,16 @@ struct ModelDownloadStatusChannel { pub async fn downloader_thread(app_data_root: AppDataRoot, app: AppHandle) -> ! { let mut status_check_queue : Arc>> = Arc::new(Mutex::new(Vec::new())); - let status_check_queue2 = status_check_queue.clone(); - tokio::spawn(download_notify_thread(status_check_queue2, app)); + { + let status_check_queue2 = status_check_queue.clone(); + let app2 = app.clone(); + + tokio::spawn(download_notify_thread(status_check_queue2, app2)); + } let mut download_queue = VecDeque::new(); - + // TODO: Automatic enqueue of known important models + enqueue new models on-demand download_queue.push_back(ModelType::ClipJson); download_queue.push_back(ModelType::SdxlTurboUnet); @@ -67,6 +72,15 @@ pub async fn downloader_thread(app_data_root: AppDataRoot, app: AppHandle) -> ! } }; + let result = app.emit(NOTIFICATION_CHANNEL_NAME, NotificationEvent::ModelDownloadStarted { + model_name: model.get_name(), + model_type: model.get_notification_type(), + }); + + if let Err(err) = result { + error!("Could not emit event: {}", err); + } + let task = tokio::spawn(download_async( url, temp_file, @@ -118,7 +132,7 @@ pub async fn download_notify_thread(queue: Arc