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