(ui: &mut egui::Ui, jobs: &mut JobQueue, appearance: &Appearance)
| 6 | use crate::views::appearance::Appearance; |
| 7 | |
| 8 | pub fn jobs_ui(ui: &mut egui::Ui, jobs: &mut JobQueue, appearance: &Appearance) { |
| 9 | if ui.button("Clear").clicked() { |
| 10 | jobs.clear_errored(); |
| 11 | } |
| 12 | |
| 13 | let mut remove_job: Option<usize> = None; |
| 14 | let mut any_jobs = false; |
| 15 | for job in jobs.iter_mut() { |
| 16 | let Ok(status) = job.context.status.read() else { |
| 17 | continue; |
| 18 | }; |
| 19 | any_jobs = true; |
| 20 | ui.separator(); |
| 21 | ui.horizontal(|ui| { |
| 22 | ui.label(&status.title); |
| 23 | if ui.small_button("✖").clicked() { |
| 24 | if job.handle.is_some() { |
| 25 | if let Err(e) = job.cancel.send(()) { |
| 26 | log::error!("Failed to cancel job: {e:?}"); |
| 27 | } |
| 28 | } else { |
| 29 | remove_job = Some(job.id); |
| 30 | } |
| 31 | } |
| 32 | }); |
| 33 | let mut bar = ProgressBar::new(status.progress_percent); |
| 34 | if let Some(items) = &status.progress_items { |
| 35 | bar = bar.text(format!("{} / {}", items[0], items[1])); |
| 36 | } |
| 37 | bar.ui(ui); |
| 38 | const STATUS_LENGTH: usize = 80; |
| 39 | if let Some(err) = &status.error { |
| 40 | let err_string = format!("{err:#}"); |
| 41 | ui.colored_label( |
| 42 | appearance.delete_color, |
| 43 | if err_string.len() > STATUS_LENGTH - 10 { |
| 44 | format!("Error: {}…", &err_string[0..STATUS_LENGTH - 10]) |
| 45 | } else { |
| 46 | format!("Error: {:width$}", err_string, width = STATUS_LENGTH - 7) |
| 47 | }, |
| 48 | ) |
| 49 | .on_hover_text_at_pointer(RichText::new(&err_string).color(appearance.delete_color)) |
| 50 | .context_menu(|ui| { |
| 51 | if ui.button("Copy full message").clicked() { |
| 52 | ui.ctx().copy_text(err_string); |
| 53 | } |
| 54 | }); |
| 55 | } else { |
| 56 | ui.label(if status.status.len() > STATUS_LENGTH - 3 { |
| 57 | format!("{}…", &status.status[0..STATUS_LENGTH - 3]) |
| 58 | } else { |
| 59 | format!("{:width$}", &status.status, width = STATUS_LENGTH) |
| 60 | }) |
| 61 | .on_hover_text_at_pointer(&status.status) |
| 62 | .context_menu(|ui| { |
| 63 | if ui.button("Copy full message").clicked() { |
| 64 | ui.ctx().copy_text(status.status.clone()); |
| 65 | } |
no test coverage detected