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

标签 notifications rust dbus freedesktop.org

我想使用 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方法的接口(interface)。根据 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我在哪里使用它。

关于notifications - 使用 dbus-rs 的 D-Bus 桌面通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29800616/

相关文章:

wpf - 在 WPF 应用程序中启动 Toastnotification

rust - 为什么使用 "Self"作为参数类型会引发生命周期错误?

python - 将 dbus.String 转换为普通字符串

c - D-Bus如何创建和发送一个Dict?

cocoa - 在终端中更改用户默认值时获取通知

wpf - 绑定(bind)到时间相关的属性

ios - 如何不让用户通过单击通知打开应用程序?

casting - 如何将 Vec<&mut T> 转换为 Vec<&T>?

rust - 为什么 `str` 是原始类型?

linux - Bluez D 总线, "StartNotify"与 "AcquireNotify"