【问题标题】:D-Bus Desktop Notification using dbus-rs使用 dbus-rs 的 D-Bus 桌面通知
【发布时间】:2015-06-30 06:59:09
【问题描述】:

我想使用 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} 让我很困惑。

【问题讨论】:

  • 我猜Array of [String]MessageItem::Array 枚举变体覆盖,但我不确定Dict。有MessageItem::DictEntry,但是说不上应该怎么用。
  • 有一个from_dict...也许Dict表示为一个键/值元组数组,而DictEntry只是一个...

标签: notifications rust dbus freedesktop.org


【解决方案1】:

一段时间后,我用@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 我在哪里使用它。

【讨论】:

    猜你喜欢
    • 2019-08-17
    • 2013-01-16
    • 2014-02-15
    • 1970-01-01
    • 2018-01-15
    • 2010-12-01
    • 2015-07-19
    • 1970-01-01
    • 2011-10-29
    相关资源
    最近更新 更多