diff --git a/docs/meli.conf.5 b/docs/meli.conf.5 index 5ee92dcd..fb9aa087 100644 --- a/docs/meli.conf.5 +++ b/docs/meli.conf.5 @@ -772,7 +772,11 @@ for the mailcap file locations. .\" default value .Pq Em m .It Ic go_to_url -Go to url of given index +Go to url of given index (with the command +.Ic url_launcher +setting in +.Sx PAGER +section) .\" default value .Pq Em g .It Ic toggle_url_mode @@ -885,6 +889,12 @@ Choose `text/html` alternative if `text/plain` is empty in `multipart/alternativ Show Date: in local timezone .\" default value .Pq Em true +.It Ic url_launcher Ar String +.Pq Em optional +A command to launch URLs with. +The URL will be given as the first argument of the command. +.\" default value +.Pq Em xdg-open .El .Sh LISTING .Bl -tag -width 36n diff --git a/src/components/mail/view.rs b/src/components/mail/view.rs index b2e04b54..2cc9c679 100644 --- a/src/components/mail/view.rs +++ b/src/components/mail/view.rs @@ -2247,7 +2247,15 @@ impl Component for MailView { } }; - match Command::new("xdg-open") + let url_launcher = mailbox_settings!( + context[self.coordinates.0][&self.coordinates.1] + .pager + .url_launcher + ) + .as_ref() + .map(|s| s.as_str()) + .unwrap_or("xdg-open"); + match Command::new(url_launcher) .arg(url) .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -2258,7 +2266,7 @@ impl Component for MailView { } Err(err) => { context.replies.push_back(UIEvent::Notification( - Some("Failed to launch xdg-open".to_string()), + Some(format!("Failed to launch {:?}", url_launcher)), err.to_string(), Some(NotificationType::Error(melib::ErrorKind::External)), )); @@ -2527,7 +2535,15 @@ impl Component for MailView { } } list_management::ListAction::Url(url) => { - match Command::new("xdg-open") + let url_launcher = mailbox_settings!( + context[self.coordinates.0][&self.coordinates.1] + .pager + .url_launcher + ) + .as_ref() + .map(|s| s.as_str()) + .unwrap_or("xdg-open"); + match Command::new(url_launcher) .arg(String::from_utf8_lossy(url).into_owned()) .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -2539,8 +2555,8 @@ impl Component for MailView { Err(err) => { context.replies.push_back(UIEvent::StatusEvent( StatusEvent::DisplayMessage(format!( - "Couldn't launch xdg-open: {}", - err + "Couldn't launch {:?}: {}", + url_launcher, err )), )); } @@ -2552,8 +2568,16 @@ impl Component for MailView { } } MailingListAction::ListArchive if actions.archive.is_some() => { - /* open archive url with xdg-open */ - match Command::new("xdg-open") + /* open archive url with url_launcher */ + let url_launcher = mailbox_settings!( + context[self.coordinates.0][&self.coordinates.1] + .pager + .url_launcher + ) + .as_ref() + .map(|s| s.as_str()) + .unwrap_or("xdg-open"); + match Command::new(url_launcher) .arg(actions.archive.unwrap()) .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -2563,8 +2587,8 @@ impl Component for MailView { Err(err) => { context.replies.push_back(UIEvent::StatusEvent( StatusEvent::DisplayMessage(format!( - "Couldn't launch xdg-open: {}", - err + "Couldn't launch {:?}: {}", + url_launcher, err )), )); } diff --git a/src/components/mail/view/envelope.rs b/src/components/mail/view/envelope.rs index 89792470..b2262fe7 100644 --- a/src/components/mail/view/envelope.rs +++ b/src/components/mail/view/envelope.rs @@ -528,15 +528,24 @@ impl Component for EnvelopeView { } }; - match Command::new("xdg-open") + let url_launcher = context + .settings + .pager + .url_launcher + .as_ref() + .map(|s| s.as_str()) + .unwrap_or("xdg-open"); + match Command::new(url_launcher) .arg(url) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn() { Ok(child) => context.children.push(child), - Err(_err) => context.replies.push_back(UIEvent::StatusEvent( - StatusEvent::DisplayMessage("Failed to start xdg_open".into()), + Err(err) => context.replies.push_back(UIEvent::Notification( + Some(format!("Failed to launch {:?}", url_launcher)), + err.to_string(), + Some(NotificationType::Error(melib::ErrorKind::External)), )), } return true; diff --git a/src/conf/overrides.rs b/src/conf/overrides.rs index 2b10540d..61822b22 100644 --- a/src/conf/overrides.rs +++ b/src/conf/overrides.rs @@ -81,6 +81,11 @@ pub struct PagerSettingsOverride { #[serde(alias = "show-date-in-my-timezone")] #[serde(default)] pub show_date_in_my_timezone: Option, + #[doc = " A command to launch URLs with. The URL will be given as the first argument of the command."] + #[doc = " Default: None"] + #[serde(deserialize_with = "non_empty_string")] + #[serde(default)] + pub url_launcher: Option>, } impl Default for PagerSettingsOverride { fn default() -> Self { @@ -96,6 +101,7 @@ impl Default for PagerSettingsOverride { minimum_width: None, auto_choose_multipart_alternative: None, show_date_in_my_timezone: None, + url_launcher: None, } } } diff --git a/src/conf/pager.rs b/src/conf/pager.rs index a76d6886..35fe8322 100644 --- a/src/conf/pager.rs +++ b/src/conf/pager.rs @@ -91,6 +91,10 @@ pub struct PagerSettings { /// Default: true #[serde(default = "internal_value_true", alias = "show-date-in-my-timezone")] pub show_date_in_my_timezone: ToggleFlag, + /// A command to launch URLs with. The URL will be given as the first argument of the command. + /// Default: None + #[serde(default = "none", deserialize_with = "non_empty_string")] + pub url_launcher: Option, } impl Default for PagerSettings { @@ -107,6 +111,7 @@ impl Default for PagerSettings { minimum_width: 80, auto_choose_multipart_alternative: ToggleFlag::InternalVal(true), show_date_in_my_timezone: ToggleFlag::InternalVal(true), + url_launcher: None, } } } @@ -129,6 +134,8 @@ impl DotAddressable for PagerSettings { "auto_choose_multipart_alternative" => { self.auto_choose_multipart_alternative.lookup(field, tail) } + "show_date_in_my_timezone" => self.show_date_in_my_timezone.lookup(field, tail), + "url_launcher" => self.html_filter.lookup(field, tail), other => Err(MeliError::new(format!( "{} has no field named {}", parent_field, other