mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
begin download handler
This commit is contained in:
@@ -13,7 +13,7 @@ use tauri::{
|
||||
// and docs ofc
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn download_file(url: &str, path: &str) -> Result<(), String> {
|
||||
pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Result<(), String> {
|
||||
// Reqwest setup
|
||||
let res = reqwest::get(url)
|
||||
.await
|
||||
@@ -42,10 +42,29 @@ pub async fn download_file(url: &str, path: &str) -> Result<(), String> {
|
||||
let new = min(downloaded + (chunk.len() as u64), total_size);
|
||||
downloaded = new;
|
||||
|
||||
let mut resHash = std::collections::HashMap::new();
|
||||
|
||||
resHash.insert(
|
||||
"downloaded".to_string(),
|
||||
downloaded.to_string()
|
||||
);
|
||||
|
||||
resHash.insert(
|
||||
"total".to_string(),
|
||||
total_size.to_string()
|
||||
);
|
||||
|
||||
resHash.insert(
|
||||
"path".to_string(),
|
||||
path.to_string()
|
||||
);
|
||||
|
||||
// Create event to send to frontend
|
||||
window.emit("download_progress", &resHash);
|
||||
}
|
||||
|
||||
// One more "finish" event
|
||||
window.emit("download_finished", &path);
|
||||
|
||||
// We are done
|
||||
return Ok(());
|
||||
|
||||
@@ -14,6 +14,7 @@ use opener;
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![run_program])
|
||||
.invoke_handler(tauri::generate_handler![downloader::download_file])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user