notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 503b7edeb555496c02b0bd41b7c5a90c034f96ee
parent 1476be48cc37016dc16c29716850270329bd7c53
Author: kernelkind <kernelkind@gmail.com>
Date:   Mon, 28 Oct 2024 16:59:21 -0400

use open instead of egui OpenUrl for mailto link

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
MCargo.lock | 37+++++++++++++++++++++++++++++++++++++
MCargo.toml | 1+
Dsrc/ui/button_hyperlink.rs | 49-------------------------------------------------
Msrc/ui/mod.rs | 1-
Msrc/ui/support.rs | 30++++++++++++++++++++----------
5 files changed, 58 insertions(+), 60 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -2068,6 +2068,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" [[package]] +name = "is-docker" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" +dependencies = [ + "once_cell", +] + +[[package]] name = "is-terminal" version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2079,6 +2088,16 @@ dependencies = [ ] [[package]] +name = "is-wsl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" +dependencies = [ + "is-docker", + "once_cell", +] + +[[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2591,6 +2610,7 @@ dependencies = [ "indexmap", "log", "nostrdb", + "open", "poll-promise", "puffin", "puffin_egui", @@ -2888,6 +2908,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] +name = "open" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a877bf6abd716642a53ef1b89fb498923a4afca5c754f9050b4d081c05c4b3" +dependencies = [ + "is-wsl", + "libc", + "pathdiff", +] + +[[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2964,6 +2995,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] +name = "pathdiff" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c5ce1153ab5b689d0c074c4e7fc613e942dfb7dd9eea5ab202d2ad91fe361" + +[[package]] name = "pbkdf2" version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -46,6 +46,7 @@ indexmap = "2.6.0" dirs = "5.0.1" tracing-appender = "0.2.3" urlencoding = "2.1.3" +open = "5.3.0" [dev-dependencies] tempfile = "3.13.0" diff --git a/src/ui/button_hyperlink.rs b/src/ui/button_hyperlink.rs @@ -1,49 +0,0 @@ -use egui::{Button, Response, Ui, Widget}; - -pub struct ButtonHyperlink<'a> { - url: String, - button: Button<'a>, - new_tab: bool, -} - -impl<'a> ButtonHyperlink<'a> { - pub fn new(button: Button<'a>, url: impl ToString) -> Self { - let url = url.to_string(); - Self { - url: url.clone(), - button, - new_tab: false, - } - } - - pub fn open_in_new_tab(mut self, new_tab: bool) -> Self { - self.new_tab = new_tab; - self - } -} - -impl<'a> Widget for ButtonHyperlink<'a> { - fn ui(self, ui: &mut Ui) -> Response { - let response = ui.add(self.button); - - if response.clicked() { - let modifiers = ui.ctx().input(|i| i.modifiers); - ui.ctx().open_url(egui::OpenUrl { - url: self.url.clone(), - new_tab: self.new_tab || modifiers.any(), - }); - } - if response.middle_clicked() { - ui.ctx().open_url(egui::OpenUrl { - url: self.url.clone(), - new_tab: true, - }); - } - - if ui.style().url_in_tooltip { - response.on_hover_text(self.url) - } else { - response - } - } -} diff --git a/src/ui/mod.rs b/src/ui/mod.rs @@ -2,7 +2,6 @@ pub mod account_login_view; pub mod account_management; pub mod add_column; pub mod anim; -pub mod button_hyperlink; pub mod mention; pub mod note; pub mod preview; diff --git a/src/ui/support.rs b/src/ui/support.rs @@ -1,4 +1,5 @@ use egui::{vec2, Button, Label, Layout, RichText}; +use tracing::error; use crate::{ app_style::{get_font_size, NotedeckTextStyle}, @@ -7,7 +8,7 @@ use crate::{ support::Support, }; -use super::{button_hyperlink::ButtonHyperlink, padding}; +use super::padding; pub struct SupportView<'a> { support: &'a mut Support, @@ -31,15 +32,18 @@ impl<'a> SupportView<'a> { ui.label("Open your default email client to get help from the Damus team"); let size = vec2(120.0, 40.0); ui.allocate_ui_with_layout(size, Layout::top_down(egui::Align::Center), |ui| { - ui.add(ButtonHyperlink::new( - Button::new( - RichText::new("Open Email") - .size(get_font_size(ui.ctx(), &NotedeckTextStyle::Body)), - ) - .fill(PINK) - .min_size(size), - self.support.get_mailto_url(), - )); + let font_size = get_font_size(ui.ctx(), &NotedeckTextStyle::Body); + let button_resp = ui.add(open_email_button(font_size, size)); + if button_resp.clicked() { + if let Err(e) = open::that(self.support.get_mailto_url()) { + error!( + "Failed to open URL {} because: {}", + self.support.get_mailto_url(), + e + ); + }; + }; + button_resp.on_hover_text_at_pointer(self.support.get_mailto_url()); }) }); @@ -74,3 +78,9 @@ impl<'a> SupportView<'a> { }); } } + +fn open_email_button(font_size: f32, size: egui::Vec2) -> impl egui::Widget { + Button::new(RichText::new("Open Email").size(font_size)) + .fill(PINK) + .min_size(size) +}