Created
December 24, 2017 09:25
-
-
Save fschutt/d143a60e70935749e4dd16777a875c0d to your computer and use it in GitHub Desktop.
Example of how to make a DBus Notification in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate dbus; | |
use dbus::{Connection, Message, BusType, MessageItem}; | |
fn main() { | |
let c = Connection::get_private(BusType::Session).unwrap(); | |
let mut m = Message::new_method_call( | |
"org.freedesktop.Notifications", | |
"/org/freedesktop/Notifications", | |
"org.freedesktop.Notifications", | |
"Notify" | |
).unwrap(); | |
let appname = "Thunderbird"; | |
let icon = "thunderbird"; | |
let summary = "Hello"; | |
let body = "This has nothing to do with emails.\nIt should not go away until you acknowledge it."; | |
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()))).unwrap(), | |
MessageItem::new_array( // hints | |
vec!( | |
MessageItem::DictEntry( | |
Box::new(MessageItem::Str("".to_string())), | |
Box::new(MessageItem::Variant( | |
Box::new(MessageItem::Str("".to_string())) | |
)) | |
), | |
) | |
).unwrap(), | |
MessageItem::Int32(50), // timeout | |
]); | |
c.send(m).unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment