tenho seguinte código tauri v2 rust use serde::{Deserialize, Serialize}; use…
- User
tenho seguinte código tauri v2 rust
use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf};
use tauri::{AppHandle, Emitter}; use reqwest::Client; use tokio::fs as tokio_fs; use tokio::io::AsyncWriteExt; use std::time::Instant;
#[derive(Debug, Deserialize)] struct PatchEntry { file_name: String, }
#[derive(Debug, Serialize, Clone)] struct DownloadMessage { message: String, }
#[derive(Debug, Serialize, Clone)] struct DownloadInfo { current_file: usize, total_files: usize, file_name: String, downloaded_bytes: u64, total_bytes: u64, }
fn get_exe_dir() -> PathBuf { std::env::current_exe() .unwrap() .parent() .unwrap() .to_path_buf() }
// Função de leitura de patches assíncrona async fn read_patch_file(path: &Path) -> Result<Vec, Box> { let content = tokio_fs::read_to_string(path).await?; let patches: Vec = serde_json::from_str(&content)?; Ok(patches) }
async fn download_file( app_handle: &AppHandle, client: &Client, entry: PatchEntry, download_dir: &Path, current_file: usize, total_files: usize, ) -> Result<(), Box> { let url = format!("https://hil-speed.hetzner.com/{}", entry.file_name); let file_path = download_dir.join(&entry.file_name);
codelet mut response = client.get(&url).send().await?; let total_bytes = response.content_length().unwrap_or(0); let mut file = tokio_fs::OpenOptions::new() .write(true) .create(true) .open(file_path) .await?; let mut downloaded_bytes = 0; let start_time = Instant::now(); app_handle.emit("download_message", DownloadMessage { message: "Baixando".to_string() })?; while let Some(chunk) = response.chunk().await? { file.write_all(&chunk).await?; downloaded_bytes += chunk.len() as u64; let elapsed_time = Instant::now().duration_since(start_time).as_secs_f64(); let speed = if elapsed_time > 0.0 { downloaded_bytes as f64 / elapsed_time } else { 0.0 }; app_handle.emit("download_info", DownloadInfo { current_file, total_files, file_name: entry.file_name.clone(), downloaded_bytes, total_bytes, })?; app_handle.emit("download_speed", speed)?; } app_handle.emit("download_message", DownloadMessage { message: "Download concluído".to_string() })?; Ok(()) - Assistant
- User
tem um problema no download, quando ele é executado como a interface tem um atraso de update ela completa primeiro e não atualiza a mensagem e mostra valores errados e para a mensagem por exemplo 99 MB / 100 MB
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.