summaryrefslogtreecommitdiffstatshomepage
path: root/src/actions/desktop_notification.rs
blob: 6ea89f7ae16670b0be4fc45791d0d13d5aa69d14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use super::Action;
use crate::message::MessageConfig;
use crate::message::MessageParams;
use anyhow::Result;
use async_trait::async_trait;

#[derive(Debug)]
pub struct DesktopNotificationAction<'a> {
    message_config: &'a MessageConfig,
}

impl<'a> DesktopNotificationAction<'a> {
    pub fn new(message_config: &'a MessageConfig) -> Self {
        Self { message_config }
    }
}

#[async_trait]
impl Action<'_> for DesktopNotificationAction<'_> {
    fn name(&self) -> &'static str {
        "desktop_notification"
    }

    async fn run(&self, params: Option<&MessageParams<'_, '_>>) -> Result<()> {
        use notify_rust::Notification;
        Notification::new()
            .summary(&self.message_config.subject(params)?)
            .body(&self.message_config.body(params)?)
            .show()?;
        Ok(())
    }
}