notifications: add new_mail_script option

Preferred over `script` option for new email notifications
issue-133
Manos Pitsidianakis 2022-09-19 21:58:59 +03:00
parent d8d43a16fe
commit 0ed10711ef
4 changed files with 36 additions and 7 deletions

View File

@ -990,8 +990,14 @@ Enable notifications.
.Pq Em optional .Pq Em optional
Script to pass notifications to, with title as 1st arg and body as 2nd Script to pass notifications to, with title as 1st arg and body as 2nd
.\" default value .\" default value
.Pq Em none Ns .Pq Em none
\&. .It Ic new_mail_script Ar String
.Pq Em optional
A command to pipe new mail notifications through (preferred over
.Ic script Ns
), with title as 1st arg and body as 2nd.
.\" default value
.Pq Em none
.It Ic xbiff_file_path Ar String .It Ic xbiff_file_path Ar String
.Pq Em optional .Pq Em optional
File that gets its size updated when new mail arrives. File that gets its size updated when new mail arrives.

View File

@ -200,7 +200,14 @@ impl Component for NotificationCommand {
} }
} }
if let Some(ref bin) = context.settings.notifications.script { let mut script = context.settings.notifications.script.as_ref();
if *kind == Some(NotificationType::NewMail)
&& context.settings.notifications.new_mail_script.is_some()
{
script = context.settings.notifications.new_mail_script.as_ref();
}
if let Some(ref bin) = script {
match Command::new(bin) match Command::new(bin)
.arg(&kind.map(|k| k.to_string()).unwrap_or_default()) .arg(&kind.map(|k| k.to_string()).unwrap_or_default())
.arg(title.as_ref().map(String::as_str).unwrap_or("meli")) .arg(title.as_ref().map(String::as_str).unwrap_or("meli"))

View File

@ -31,17 +31,26 @@ pub struct NotificationsSettings {
/// Default: True /// Default: True
#[serde(default = "true_val")] #[serde(default = "true_val")]
pub enable: bool, pub enable: bool,
/// A command to pipe notifications through
/// A command to pipe notifications through.
/// Default: None /// Default: None
#[serde(default = "none")] #[serde(default = "none")]
pub script: Option<String>, pub script: Option<String>,
/// A command to pipe new mail notifications through (preferred over `script`).
/// Default: None
#[serde(default = "none")]
pub new_mail_script: Option<String>,
/// A file location which has its size changed when new mail arrives (max 128 bytes). Can be /// A file location which has its size changed when new mail arrives (max 128 bytes). Can be
/// used to trigger new mail notifications eg with `xbiff(1)` /// used to trigger new mail notifications eg with `xbiff(1)`.
/// Default: None /// Default: None
#[serde(default = "none", alias = "xbiff-file-path")] #[serde(default = "none", alias = "xbiff-file-path")]
pub xbiff_file_path: Option<String>, pub xbiff_file_path: Option<String>,
#[serde(default = "internal_value_false", alias = "play-sound")] #[serde(default = "internal_value_false", alias = "play-sound")]
pub play_sound: ToggleFlag, pub play_sound: ToggleFlag,
#[serde(default = "none", alias = "sound-file")] #[serde(default = "none", alias = "sound-file")]
pub sound_file: Option<String>, pub sound_file: Option<String>,
} }
@ -51,6 +60,7 @@ impl Default for NotificationsSettings {
Self { Self {
enable: true, enable: true,
script: None, script: None,
new_mail_script: None,
xbiff_file_path: None, xbiff_file_path: None,
play_sound: ToggleFlag::InternalVal(false), play_sound: ToggleFlag::InternalVal(false),
sound_file: None, sound_file: None,
@ -65,6 +75,7 @@ impl DotAddressable for NotificationsSettings {
match *field { match *field {
"enable" => self.enable.lookup(field, tail), "enable" => self.enable.lookup(field, tail),
"script" => self.script.lookup(field, tail), "script" => self.script.lookup(field, tail),
"new_mail_script" => self.new_mail_script.lookup(field, tail),
"xbiff_file_path" => self.xbiff_file_path.lookup(field, tail), "xbiff_file_path" => self.xbiff_file_path.lookup(field, tail),
"play_sound" => self.play_sound.lookup(field, tail), "play_sound" => self.play_sound.lookup(field, tail),
"sound_file" => self.sound_file.lookup(field, tail), "sound_file" => self.sound_file.lookup(field, tail),

View File

@ -214,12 +214,16 @@ pub struct NotificationsSettingsOverride {
#[doc = " Default: True"] #[doc = " Default: True"]
#[serde(default)] #[serde(default)]
pub enable: Option<bool>, pub enable: Option<bool>,
#[doc = " A command to pipe notifications through"] #[doc = " A command to pipe notifications through."]
#[doc = " Default: None"] #[doc = " Default: None"]
#[serde(default)] #[serde(default)]
pub script: Option<Option<String>>, pub script: Option<Option<String>>,
#[doc = " A command to pipe new mail notifications through (preferred over `script`)."]
#[doc = " Default: None"]
#[serde(default)]
pub new_mail_script: Option<Option<String>>,
#[doc = " A file location which has its size changed when new mail arrives (max 128 bytes). Can be"] #[doc = " A file location which has its size changed when new mail arrives (max 128 bytes). Can be"]
#[doc = " used to trigger new mail notifications eg with `xbiff(1)`"] #[doc = " used to trigger new mail notifications eg with `xbiff(1)`."]
#[doc = " Default: None"] #[doc = " Default: None"]
#[serde(alias = "xbiff-file-path")] #[serde(alias = "xbiff-file-path")]
#[serde(default)] #[serde(default)]
@ -236,6 +240,7 @@ impl Default for NotificationsSettingsOverride {
NotificationsSettingsOverride { NotificationsSettingsOverride {
enable: None, enable: None,
script: None, script: None,
new_mail_script: None,
xbiff_file_path: None, xbiff_file_path: None,
play_sound: None, play_sound: None,
sound_file: None, sound_file: None,