SNot/src/main.rs

49 lines
1.8 KiB
Rust
Raw Normal View History

2024-08-26 18:51:37 +00:00
use std::collections::HashMap;
use zbus::blocking::{Connection, MessageIterator};
2024-08-25 21:10:15 +00:00
use zbus::fdo::Result;
2024-08-26 18:51:37 +00:00
use zbus::zvariant::Value;
2024-08-25 21:10:15 +00:00
use zbus::MatchRule;
fn main() -> Result<()> {
// Establish a connection to the session bus
let connection = Connection::session()?;
2024-08-26 18:51:37 +00:00
// Create a match rule for the Notify signal
2024-08-25 21:10:15 +00:00
let match_rule = MatchRule::builder()
2024-08-26 18:51:37 +00:00
.msg_type(zbus::message::Type::Signal)
2024-08-25 21:10:15 +00:00
.interface("org.freedesktop.Notifications")?
2024-08-26 18:51:37 +00:00
.member("Notify")?
2024-08-25 21:10:15 +00:00
.build();
2024-08-23 02:18:27 +00:00
2024-08-26 18:51:37 +00:00
// Create a message iterator for the match rule
let mut iterator = MessageIterator::for_match_rule(match_rule, &connection, None)?;
2024-08-20 04:56:36 +00:00
2024-08-26 18:51:37 +00:00
// Loop to handle incoming messages
while let Some(result) = iterator.next() {
match result {
Ok(msg) => {
// Extract the body of the message
let body_result: Result<(String, u32, String, String, String, Vec<String>, HashMap<String, Value>, i32), _> = msg.body();
match body_result {
Ok((app_name, id, summary, body, icon, actions, hints, timeout)) => {
println!("Got notification:");
println!(" App Name: {}", app_name);
println!(" ID: {}", id);
println!(" Summary: {}", summary);
println!(" Body: {}", body);
println!(" Icon: {}", icon);
println!(" Actions: {:?}", actions);
println!(" Hints: {:?}", hints);
println!(" Timeout: {}", timeout);
},
Err(e) => println!("Error decoding message body: {:?}", e),
}
2024-08-25 21:10:15 +00:00
}
2024-08-26 18:51:37 +00:00
Err(e) => println!("Error receiving message: {:?}", e),
}
}
2024-08-26 11:16:10 +00:00
Ok(())
}