Module ashpd::desktop::notification

source ·
Expand description

Send/withdraw notifications.

§Examples

use std::{thread, time};

use ashpd::desktop::{
    notification::{Action, Button, Notification, NotificationProxy, Priority},
    Icon,
};
use futures_util::StreamExt;
use zbus::zvariant::Value;

async fn run() -> ashpd::Result<()> {
    let proxy = NotificationProxy::new().await?;

    let notification_id = "org.gnome.design.Contrast";
    proxy
        .add_notification(
            notification_id,
            Notification::new("Contrast")
                .default_action("open")
                .default_action_target(100)
                .body("color copied to clipboard")
                .priority(Priority::High)
                .icon(Icon::with_names(&["dialog-question-symbolic"]))
                .button(Button::new("Copy", "copy").target(32))
                .button(Button::new("Delete", "delete").target(40)),
        )
        .await?;

    let action = proxy
        .receive_action_invoked()
        .await?
        .next()
        .await
        .expect("Stream exhausted");
    match action.name() {
        "copy" => (),   // Copy something to clipboard
        "delete" => (), // Delete the file
        _ => (),
    };
    println!("{:#?}", action.id());
    println!(
        "{:#?}",
        action.parameter().get(0).unwrap().downcast_ref::<u32>()
    );

    proxy.remove_notification(notification_id).await?;
    Ok(())
}

Structs§

Enums§