(window: Window, model: transcriber::Model)
| 206 | |
| 207 | #[tauri::command] |
| 208 | fn download_model(window: Window, model: transcriber::Model) -> String { |
| 209 | let channel_name = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos().to_string(); |
| 210 | |
| 211 | println!("Downloading model {model:?}"); |
| 212 | |
| 213 | let channel = channel_name.clone(); |
| 214 | tauri::async_runtime::spawn(async move { |
| 215 | let mut response = reqwest::get(model.download_url()).await.unwrap(); |
| 216 | |
| 217 | let mut file = std::fs::File::create(model.path()).unwrap(); |
| 218 | |
| 219 | let mut downloaded_size = 0; |
| 220 | let predicted_size = response.content_length().unwrap_or((model.disk_usage() * 1000000) as _); |
| 221 | |
| 222 | while let Some(chunk) = match response.chunk().await { |
| 223 | Ok(chunk) => chunk, |
| 224 | Err(err) => { |
| 225 | window.emit(&channel, serde_json::json!({ |
| 226 | "type": "error", |
| 227 | "value": format!("{err:?}"), |
| 228 | })).unwrap(); |
| 229 | return; |
| 230 | }, |
| 231 | } { |
| 232 | match file.write(&chunk) { |
| 233 | Ok(length) => downloaded_size += dbg!(length), |
| 234 | Err(err) => window.emit(&channel, serde_json::json!({ |
| 235 | "type": "error", |
| 236 | "value": format!("{err:?}"), |
| 237 | })).unwrap(), |
| 238 | } |
| 239 | |
| 240 | window.emit(&channel, serde_json::json!({ |
| 241 | "type": "progress", |
| 242 | "value": (downloaded_size as f32 / (predicted_size) as f32) * 100.0, |
| 243 | })).unwrap(); |
| 244 | } |
| 245 | |
| 246 | window.emit(&channel, serde_json::json!({ |
| 247 | "type": "done", |
| 248 | "value": "", |
| 249 | })).unwrap(); |
| 250 | }); |
| 251 | |
| 252 | channel_name |
| 253 | } |
| 254 | |
| 255 | #[tauri::command] |
| 256 | fn select_language(transcriber: State<'_, Arc<Mutex<transcriber::Transcriber>>>, language: String) { |
nothing calls this directly
no test coverage detected