使用 dbus-rs 的 D-Bus 桌面通知

D-Bus Desktop Notification using dbus-rs

我想使用 https://crates.io/crates/dbus 通过 D-BUS 发送桌面通知。

我目前的做法是:

    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

]);

我想不出有意义的方式来满足Notify方法的接口。根据 D-Feet 的说法,它看起来像这样:

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

尤其是Array of [String]Dict of {String, Variant}让我很困惑。

过了一会儿,我用@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
               ]);

我的 little fun project 我用它的地方。