more trial and error

This commit is contained in:
Candifloss 2024-08-27 00:21:37 +05:30
parent 71fa793480
commit 3ca662b591
3 changed files with 52 additions and 34 deletions

View File

@ -6,5 +6,6 @@ authors = ["candifloss <candifloss.cc>"]
[dependencies] [dependencies]
zbus = "4.4.0" zbus = "4.4.0"
zbus_names = "*"
# rson_rs = "0.2.1" # rson_rs = "0.2.1"
tokio = "1.39.3" tokio = "1.39.3"

View File

@ -1,48 +1,48 @@
//use zbus::blocking::Connection; use std::collections::HashMap;
use zbus::Connection; use zbus::blocking::{Connection, MessageIterator};
use zbus::fdo::Result; use zbus::fdo::Result;
use zbus::Message; use zbus::zvariant::Value;
use zbus::MatchRule; use zbus::MatchRule;
use zbus::blocking::Proxy;
use zbus::MessageStream;
//use futures_util::stream::TryStreamExt;
fn main() -> Result<()> { fn main() -> Result<()> {
// Establish a connection to the session bus // Establish a connection to the session bus
let connection = Connection::session()?; let connection = Connection::session()?;
// Proxy // Create a match rule for the Notify signal
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
let match_rule = MatchRule::builder() let match_rule = MatchRule::builder()
.msg_type(zbus::MessageType::Signal) .msg_type(zbus::message::Type::Signal)
.interface("org.freedesktop.Notifications")? .interface("org.freedesktop.Notifications")?
.path("/org/freedesktop/Notifications")? .member("Notify")?
.build(); .build();
// Add the match rule to the connection // Create a message iterator for the match rule
//connection.add_match(match_rule)?; let mut iterator = MessageIterator::for_match_rule(match_rule, &connection, None)?;
let mut stream = MessageStream::from(connection); // Loop to handle incoming messages
while let Some(msg) = stream.body? { while let Some(result) = iterator.next() {
println!("Got message: {}", msg); match result {
} Ok(msg) => {
// Process notifications // Extract the body of the message
/*loop { let body_result: Result<(String, u32, String, String, String, Vec<String>, HashMap<String, Value>, i32), _> = msg.body();
/*
let message = connection.receive_signal()?; match body_result {
if let Some(member) = message.member() { Ok((app_name, id, summary, body, icon, actions, hints, timeout)) => {
if member.as_str() == "Notify" { println!("Got notification:");
println!("Received a notification: {:?}", message); 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(()) Ok(())
} }

View File

@ -129,4 +129,21 @@ fn truncate_summary(notif: &mut Notif) {
notif.summary.truncate(39); notif.summary.truncate(39);
notif.summary.push('…'); notif.summary.push('…');
} }
} }
/*/ 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
)?;