support.rs (3416B)
1 use egui::{vec2, Button, Label, Layout, RichText}; 2 use tracing::error; 3 4 use crate::{ 5 app_style::{get_font_size, NotedeckTextStyle}, 6 colors::PINK, 7 fonts::NamedFontFamily, 8 support::Support, 9 }; 10 11 use super::padding; 12 13 pub struct SupportView<'a> { 14 support: &'a mut Support, 15 } 16 17 impl<'a> SupportView<'a> { 18 pub fn new(support: &'a mut Support) -> Self { 19 Self { support } 20 } 21 22 pub fn show(&mut self, ui: &mut egui::Ui) { 23 padding(8.0, ui, |ui| { 24 ui.spacing_mut().item_spacing = egui::vec2(0.0, 8.0); 25 let font = egui::FontId::new( 26 get_font_size(ui.ctx(), &NotedeckTextStyle::Body), 27 egui::FontFamily::Name(NamedFontFamily::Bold.as_str().into()), 28 ); 29 ui.add(Label::new(RichText::new("Running into a bug?").font(font))); 30 ui.label(RichText::new("Step 1").text_style(NotedeckTextStyle::Heading3.text_style())); 31 padding(8.0, ui, |ui| { 32 ui.label("Open your default email client to get help from the Damus team"); 33 let size = vec2(120.0, 40.0); 34 ui.allocate_ui_with_layout(size, Layout::top_down(egui::Align::Center), |ui| { 35 let font_size = get_font_size(ui.ctx(), &NotedeckTextStyle::Body); 36 let button_resp = ui.add(open_email_button(font_size, size)); 37 if button_resp.clicked() { 38 if let Err(e) = open::that(self.support.get_mailto_url()) { 39 error!( 40 "Failed to open URL {} because: {}", 41 self.support.get_mailto_url(), 42 e 43 ); 44 }; 45 }; 46 button_resp.on_hover_text_at_pointer(self.support.get_mailto_url()); 47 }) 48 }); 49 50 ui.add_space(8.0); 51 52 if let Some(logs) = self.support.get_most_recent_log() { 53 ui.label( 54 RichText::new("Step 2").text_style(NotedeckTextStyle::Heading3.text_style()), 55 ); 56 let size = vec2(80.0, 40.0); 57 let copy_button = Button::new( 58 RichText::new("Copy").size(get_font_size(ui.ctx(), &NotedeckTextStyle::Body)), 59 ) 60 .fill(PINK) 61 .min_size(size); 62 padding(8.0, ui, |ui| { 63 ui.add(Label::new("Press the button below to copy your most recent logs to your system's clipboard. Then paste it into your email.").wrap()); 64 ui.allocate_ui_with_layout(size, Layout::top_down(egui::Align::Center), |ui| { 65 if ui.add(copy_button).clicked() { 66 ui.output_mut(|w| { 67 w.copied_text = logs.to_string(); 68 }); 69 } 70 }); 71 }); 72 } else { 73 ui.label( 74 egui::RichText::new("ERROR: Could not find logs on system") 75 .color(egui::Color32::RED), 76 ); 77 } 78 }); 79 } 80 } 81 82 fn open_email_button(font_size: f32, size: egui::Vec2) -> impl egui::Widget { 83 Button::new(RichText::new("Open Email").size(font_size)) 84 .fill(PINK) 85 .min_size(size) 86 }