Add url_launcher config setting

Manos Pitsidianakis 2021-09-16 16:43:43 +03:00
parent b88c3c573d
commit f975e1004c
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 69 additions and 13 deletions

View File

@ -772,7 +772,11 @@ for the mailcap file locations.
.\" default value .\" default value
.Pq Em m .Pq Em m
.It Ic go_to_url .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 .\" default value
.Pq Em g .Pq Em g
.It Ic toggle_url_mode .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 Show Date: in local timezone
.\" default value .\" default value
.Pq Em true .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 .El
.Sh LISTING .Sh LISTING
.Bl -tag -width 36n .Bl -tag -width 36n

View File

@ -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) .arg(url)
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
@ -2258,7 +2266,7 @@ impl Component for MailView {
} }
Err(err) => { Err(err) => {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
Some("Failed to launch xdg-open".to_string()), Some(format!("Failed to launch {:?}", url_launcher)),
err.to_string(), err.to_string(),
Some(NotificationType::Error(melib::ErrorKind::External)), Some(NotificationType::Error(melib::ErrorKind::External)),
)); ));
@ -2527,7 +2535,15 @@ impl Component for MailView {
} }
} }
list_management::ListAction::Url(url) => { 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()) .arg(String::from_utf8_lossy(url).into_owned())
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
@ -2539,8 +2555,8 @@ impl Component for MailView {
Err(err) => { Err(err) => {
context.replies.push_back(UIEvent::StatusEvent( context.replies.push_back(UIEvent::StatusEvent(
StatusEvent::DisplayMessage(format!( StatusEvent::DisplayMessage(format!(
"Couldn't launch xdg-open: {}", "Couldn't launch {:?}: {}",
err url_launcher, err
)), )),
)); ));
} }
@ -2552,8 +2568,16 @@ impl Component for MailView {
} }
} }
MailingListAction::ListArchive if actions.archive.is_some() => { MailingListAction::ListArchive if actions.archive.is_some() => {
/* open archive url with xdg-open */ /* open archive url with url_launcher */
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(actions.archive.unwrap()) .arg(actions.archive.unwrap())
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
@ -2563,8 +2587,8 @@ impl Component for MailView {
Err(err) => { Err(err) => {
context.replies.push_back(UIEvent::StatusEvent( context.replies.push_back(UIEvent::StatusEvent(
StatusEvent::DisplayMessage(format!( StatusEvent::DisplayMessage(format!(
"Couldn't launch xdg-open: {}", "Couldn't launch {:?}: {}",
err url_launcher, err
)), )),
)); ));
} }

View File

@ -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) .arg(url)
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn() .spawn()
{ {
Ok(child) => context.children.push(child), Ok(child) => context.children.push(child),
Err(_err) => context.replies.push_back(UIEvent::StatusEvent( Err(err) => context.replies.push_back(UIEvent::Notification(
StatusEvent::DisplayMessage("Failed to start xdg_open".into()), Some(format!("Failed to launch {:?}", url_launcher)),
err.to_string(),
Some(NotificationType::Error(melib::ErrorKind::External)),
)), )),
} }
return true; return true;

View File

@ -81,6 +81,11 @@ pub struct PagerSettingsOverride {
#[serde(alias = "show-date-in-my-timezone")] #[serde(alias = "show-date-in-my-timezone")]
#[serde(default)] #[serde(default)]
pub show_date_in_my_timezone: Option<ToggleFlag>, pub show_date_in_my_timezone: Option<ToggleFlag>,
#[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<Option<String>>,
} }
impl Default for PagerSettingsOverride { impl Default for PagerSettingsOverride {
fn default() -> Self { fn default() -> Self {
@ -96,6 +101,7 @@ impl Default for PagerSettingsOverride {
minimum_width: None, minimum_width: None,
auto_choose_multipart_alternative: None, auto_choose_multipart_alternative: None,
show_date_in_my_timezone: None, show_date_in_my_timezone: None,
url_launcher: None,
} }
} }
} }

View File

@ -91,6 +91,10 @@ pub struct PagerSettings {
/// Default: true /// Default: true
#[serde(default = "internal_value_true", alias = "show-date-in-my-timezone")] #[serde(default = "internal_value_true", alias = "show-date-in-my-timezone")]
pub show_date_in_my_timezone: ToggleFlag, 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<String>,
} }
impl Default for PagerSettings { impl Default for PagerSettings {
@ -107,6 +111,7 @@ impl Default for PagerSettings {
minimum_width: 80, minimum_width: 80,
auto_choose_multipart_alternative: ToggleFlag::InternalVal(true), auto_choose_multipart_alternative: ToggleFlag::InternalVal(true),
show_date_in_my_timezone: 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" => { "auto_choose_multipart_alternative" => {
self.auto_choose_multipart_alternative.lookup(field, tail) 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!( other => Err(MeliError::new(format!(
"{} has no field named {}", "{} has no field named {}",
parent_field, other parent_field, other