Skip to content

I need help!

I am creating a launcher using the library but, when doing this step and waiting for a response from the FrontEnd, it does not send anything and the function stops once it finishes downloading the Libraries content

Code:

#[tauri::command] async fn download_pt3(data: Requeriments, window: tauri::Window) -> Result<(), String> { let _ = window.emit("download_status_c", json!({ "completed": false, "status": "Updating instance...", "progress": 0, "downloading": false }));

let new_instance = PathBuf::from(data.instances_dir.clone()).join(data.name.clone()); let libraries_path = new_instance.join("libraries"); let assets_path = new_instance.join("assets");

let current_fabric = get_fabric_loader_version(data.version.clone()).await.unwrap(); let fabric_loader_version = current_fabric["loader"]["version"].as_str().unwrap_or("unknown").to_string();

let rem = get_total_sys_mem().parse::().unwrap(); let totalram = rem * 1024; let totalram = Number::from(totalram);

let mut instance = InstanceBuilder::default() .name(data.name.clone()) .version(data.version.clone()) .instance_path(new_instance.clone()) .libraries_path(libraries_path.clone()) .assets_path(assets_path.clone()) .fullscreen(true) .enable_custom_memory(true) .custom_min_memory((totalram.as_u64().unwrap() - (6 * 1024)) as u32) .custom_max_memory((totalram.as_u64().unwrap() - (2 * 1024)) as u32) .fabric_version(Some(fabric_loader_version)) .build() .unwrap();

let (tx, rx) = InstallationUpdate::channel(500);

let (install_result, _) = tokio::join! { instance.full_installation(1, 5, true, tx.clone()), process_updates_instance(window.clone(), rx) };

if let Err(e) = install_result { eprintln!("Error during installation: {}", e); }

println!("{}", instance.installed);

// println!("Instance installed successfully"); // println!("Sending instance data to the main thread..."); // let _ = window.emit("download_status_c", json!({ // "completed": false, // "completed_c": true, // "status": "Instance updated successfully", // "downloading": false // }));

Ok(()) }

async fn process_updates_instance(window: tauri::Window ,mut rx: tokio::sync::mpsc::Receiver){ while let Some(update) = rx.recv().await { match update { InstallationUpdate::Library((n,p)) => match p { LibraryInstallationUpdate::Downloading(p) => print_process_instance(window.clone(), p, "Libraries".to_string()), LibraryInstallationUpdate::Extracting => print_extracting_instance(window.clone(), n, "Libraries".to_string()), } InstallationUpdate::Asset((n,p)) => match p { AssetInstallationUpdate::Downloading(p) => print_process_instance(window.clone(), p, "Assets".to_string()), AssetInstallationUpdate::Symlink => print_extracting_instance(window.clone(), n, "Assets".to_string()), } InstallationUpdate::LogConfig(p) => match p { LogConfigInstallationUpdate::Downloading(p) => print_process_instance(window.clone(), p, "Log Config".to_string()), } InstallationUpdate::Client(p) => match p { ClientInstallationUpdate::Downloading(p) => print_process_instance(window.clone(), p, "SpreenClient Libs".to_string()), } } } }

fn print_extracting_instance(window: tauri::Window, p: String, invokator: String){ tauri::async_runtime::spawn_blocking(move || { let _ = window.emit("download_status_c", json!({ "completed": false, "tx": p, "status": format!("Extracting {}", invokator), "extracting": true, "downloading": true })); }); }

fn print_process_instance(window: tauri::Window, p: DownloadProgress, invokator: String){ let name = p.file.file_name().map(|s| s.to_string_lossy().to_string()).unwrap();

tauri::async_runtime::spawn_blocking(move || { let _ = window.emit("download_status_c", json!({ "completed": false, "status": format!("Patching {}", invokator), "currentfileindex": p.current_file + 1, "totalfiles": p.total_files, "namefile": name, "max": p.total_bytes, "extracting": false, "progress": p.downloaded_bytes, "downloading": true })); }); }

Edited by notzairdev