support.rs (4799B)
1 use crate::support::{Support, SUPPORT_EMAIL}; 2 use egui::{vec2, Button, Label, Layout, RichText}; 3 use notedeck::{tr, Localization, NamedFontFamily, NotedeckTextStyle}; 4 use notedeck_ui::{colors::PINK, padding}; 5 use robius_open::Uri; 6 use tracing::error; 7 8 pub struct SupportView<'a> { 9 support: &'a mut Support, 10 i18n: &'a mut Localization, 11 } 12 13 impl<'a> SupportView<'a> { 14 pub fn new(support: &'a mut Support, i18n: &'a mut Localization) -> Self { 15 Self { support, i18n } 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( 26 RichText::new(tr!( 27 self.i18n, 28 "Running into a bug?", 29 "Heading for support section" 30 )) 31 .font(font), 32 )); 33 ui.label( 34 RichText::new(tr!( 35 self.i18n, 36 "Step 1", 37 "Step 1 label in support instructions" 38 )) 39 .text_style(NotedeckTextStyle::Heading3.text_style()), 40 ); 41 padding(8.0, ui, |ui| { 42 ui.label(tr!( 43 self.i18n, 44 "Open your default email client to get help from the Damus team", 45 "Instruction to open email client" 46 )); 47 48 ui.horizontal_wrapped(|ui| { 49 ui.label(tr!(self.i18n, "Support email:", "Support email address",)); 50 ui.label(RichText::new(SUPPORT_EMAIL).color(PINK)) 51 }); 52 53 let size = vec2(120.0, 40.0); 54 ui.allocate_ui_with_layout(size, Layout::top_down(egui::Align::Center), |ui| { 55 let font_size = 56 notedeck::fonts::get_font_size(ui.ctx(), &NotedeckTextStyle::Body); 57 let button_resp = ui.add(open_email_button(self.i18n, font_size, size)); 58 if button_resp.clicked() { 59 if let Err(e) = Uri::new(self.support.get_mailto_url()).open() { 60 error!( 61 "Failed to open URL {} because: {:?}", 62 self.support.get_mailto_url(), 63 e 64 ); 65 }; 66 }; 67 button_resp.on_hover_text_at_pointer(self.support.get_mailto_url()); 68 }) 69 }); 70 71 ui.add_space(8.0); 72 73 if let Some(logs) = self.support.get_most_recent_log() { 74 ui.label( 75 RichText::new(tr!( 76 self.i18n, 77 "Step 2", 78 "Step 2 label in support instructions" 79 )) 80 .text_style(NotedeckTextStyle::Heading3.text_style()), 81 ); 82 let size = vec2(80.0, 40.0); 83 let copy_button = Button::new( 84 RichText::new(tr!(self.i18n, "Copy", "Button label to copy logs")).size( 85 notedeck::fonts::get_font_size(ui.ctx(), &NotedeckTextStyle::Body), 86 ), 87 ) 88 .fill(PINK) 89 .min_size(size); 90 padding(8.0, ui, |ui| { 91 ui.add(Label::new(RichText::new(tr!(self.i18n,"Press the button below to copy your most recent logs to your system's clipboard. Then paste it into your email.", "Instruction for copying logs"))).wrap()); 92 ui.allocate_ui_with_layout(size, Layout::top_down(egui::Align::Center), |ui| { 93 if ui.add(copy_button).clicked() { 94 ui.ctx().copy_text(logs.to_string()); 95 } 96 }); 97 }); 98 } else { 99 ui.label( 100 egui::RichText::new("ERROR: Could not find logs on system") 101 .color(egui::Color32::RED), 102 ); 103 } 104 ui.label(format!("Notedeck {}", env!("CARGO_PKG_VERSION"))); 105 ui.label(format!("Commit hash: {}", env!("GIT_COMMIT_HASH"))); 106 }); 107 } 108 } 109 110 fn open_email_button( 111 i18n: &mut Localization, 112 font_size: f32, 113 size: egui::Vec2, 114 ) -> impl egui::Widget { 115 Button::new( 116 RichText::new(tr!(i18n, "Open Email", "Button label to open email client")).size(font_size), 117 ) 118 .fill(PINK) 119 .min_size(size) 120 }