D-Bus Desktop Notification using dbus-rs
Asked Answered
S

1

7

I would like to send desktop notifications through D-BUS using https://crates.io/crates/dbus.

My current approach is:

    let c = Connection::get_private(BusType::Session).unwrap();
//let m = Message::new_method_call("org.freedesktop.DBus", "/", "org.freedesktop.DBus", "ListNames").unwrap();
let mut m = Message::new_method_call(
    "org.freedesktop.Notifications",
    "/org/freedesktop/Notifications",
    "org.freedesktop.Notifications",
    "Notify"
    ).unwrap();
m.append_items(&[
       MessageItem::Str("appname".to_string()),         // appname
       MessageItem::UInt32(0),                          // notification to update
       MessageItem::Str("icon".to_string()),            // icon
       MessageItem::Str("summary".to_string()),         // summary (title)
       MessageItem::Str("body".to_string()),            // body
       ???,                                             // actions
       ???,                                             // hints
       MessageItem::UInt32(9000),                       // timeout

]);

I can't think of a meaningful way to satisfy the interface of the Notify method. According to D-Feet, it looks like this:

Notify(
    String app_name,
    UInt32 replaces_id,
    String app_icon,
    String summary,
    String body,
    Array of [String] actions,
    Dict of {String, Variant} hints,
    Int32
)

Especially the Array of [String], Dict of {String, Variant} puzzles me.

Sugary answered 22/4, 2015 at 14:23 Comment(2)
I guess Array of [String] is covered by MessageItem::Array enum variant, but I'm not sure about Dict. There is MessageItem::DictEntry, but I can't say how it should be used.Thatch
There is a from_dict... perhaps Dict is represented as an array of key/value tuples, and DictEntry is just a single one...Involution
S
2

After a while I figured this out with @payload

    m.append_items(&[
                   MessageItem::Str(appname.to_string()),         // appname
                   MessageItem::UInt32(0),                        // notification to update
                   MessageItem::Str(icon.to_string()),            // icon
                   MessageItem::Str(summary.to_string()),         // summary (title)
                   MessageItem::Str(body.to_string()),            // body
                   MessageItem::new_array(                        // actions
                       vec!( MessageItem::Str("".to_string()))),
                   MessageItem::new_array(                        // hints
                       vec!(
                           MessageItem::DictEntry(
                               Box::new(MessageItem::Str("".to_string())),
                               Box::new(MessageItem::Variant(
                                       Box::new(MessageItem::Str("".to_string()))
                                       ))
                           ),
                       )
                   ),
                   MessageItem::Int32(9000),                       // timeout
               ]);

My little fun project where I use this.

Sugary answered 20/5, 2015 at 22:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.