2024-06-23 15:07:25 -06:00
|
|
|
use std::clone;
|
2024-10-23 22:24:50 -06:00
|
|
|
use tauri::Emitter;
|
2024-06-22 17:52:25 -06:00
|
|
|
|
2024-06-23 15:07:25 -06:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
#[derive(Clone, Serialize)]
|
|
|
|
pub struct DownloadStatus {
|
|
|
|
downloaded: usize,
|
|
|
|
total: usize,
|
|
|
|
time_elapsed: usize,
|
2024-10-23 22:24:50 -06:00
|
|
|
download_name: String,
|
2024-06-23 15:07:25 -06:00
|
|
|
}
|
|
|
|
|
2024-10-23 22:24:50 -06:00
|
|
|
pub fn download_callback(
|
|
|
|
download_name: String,
|
|
|
|
window: Option<tauri::AppHandle>,
|
|
|
|
count: usize,
|
|
|
|
size: usize,
|
|
|
|
) {
|
|
|
|
unsafe {
|
2024-06-23 15:07:25 -06:00
|
|
|
static mut total: usize = 0;
|
|
|
|
total += count;
|
|
|
|
if let Some(window1) = window.clone() {
|
2024-10-23 22:24:50 -06:00
|
|
|
window1.emit(
|
|
|
|
"download_progress",
|
|
|
|
DownloadStatus {
|
|
|
|
downloaded: total,
|
|
|
|
total: size,
|
|
|
|
time_elapsed: 0,
|
|
|
|
download_name: download_name,
|
|
|
|
},
|
|
|
|
);
|
2024-06-23 15:07:25 -06:00
|
|
|
}
|
2024-10-23 22:24:50 -06:00
|
|
|
println!(
|
|
|
|
"Downloading {}MB / {}MB",
|
|
|
|
total / (1024 * 1024),
|
|
|
|
size / (1024 * 1024)
|
|
|
|
);
|
2024-06-23 15:07:25 -06:00
|
|
|
if count == 0 {
|
|
|
|
if let Some(window2) = window {
|
|
|
|
window2.emit("download_finished", true);
|
|
|
|
}
|
|
|
|
total = 0;
|
|
|
|
}
|
|
|
|
}
|
2024-06-22 17:52:25 -06:00
|
|
|
}
|