diff --git a/Cargo.toml b/Cargo.toml index f1a880c..e6d9fae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,6 @@ authors = ["candifloss "] [dependencies] zbus = "4.4.0" +zbus_names = "*" # rson_rs = "0.2.1" tokio = "1.39.3" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index de1f886..bcd6f03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,48 +1,48 @@ -//use zbus::blocking::Connection; -use zbus::Connection; +use std::collections::HashMap; +use zbus::blocking::{Connection, MessageIterator}; use zbus::fdo::Result; -use zbus::Message; +use zbus::zvariant::Value; use zbus::MatchRule; -use zbus::blocking::Proxy; -use zbus::MessageStream; -//use futures_util::stream::TryStreamExt; fn main() -> Result<()> { // Establish a connection to the session bus let connection = Connection::session()?; - // Proxy - let prox = Proxy::new( - &connection, - "org.freedesktop.Notifications", // Service/Bus name - "/org/freedesktop/Notifications", // Object path - "org.freedesktop.Notifications", // Interface name - )?; - - // Define a match rule for the notifications + // Create a match rule for the Notify signal let match_rule = MatchRule::builder() - .msg_type(zbus::MessageType::Signal) + .msg_type(zbus::message::Type::Signal) .interface("org.freedesktop.Notifications")? - .path("/org/freedesktop/Notifications")? + .member("Notify")? .build(); - // Add the match rule to the connection - //connection.add_match(match_rule)?; + // Create a message iterator for the match rule + let mut iterator = MessageIterator::for_match_rule(match_rule, &connection, None)?; - let mut stream = MessageStream::from(connection); - while let Some(msg) = stream.body? { - println!("Got message: {}", msg); - } - // Process notifications - /*loop { - /* - let message = connection.receive_signal()?; - if let Some(member) = message.member() { - if member.as_str() == "Notify" { - println!("Received a notification: {:?}", message); + // 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, HashMap, 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), + } } - } */ - - }*/ + Err(e) => println!("Error receiving message: {:?}", e), + } + } + Ok(()) } diff --git a/src/unused.txt b/src/unused.txt index 71a8f3b..34f27f1 100644 --- a/src/unused.txt +++ b/src/unused.txt @@ -129,4 +129,21 @@ fn truncate_summary(notif: &mut Notif) { notif.summary.truncate(39); notif.summary.push('…'); } -} \ No newline at end of file +} + + + /*/ Define a match rule for the notifications + let match_rule = MatchRule::builder() + .msg_type(zbus::MessageType::Signal) + .interface("org.freedesktop.Notifications")? + .path("/org/freedesktop/Notifications")? + .build();*/ + + + // Proxy + let proxy = Proxy::new( + &connection, + "org.freedesktop.Notifications", // Service/Bus name + "/org/freedesktop/Notifications", // Object path + "org.freedesktop.Notifications", // Interface name + )?; \ No newline at end of file