more trial and error
This commit is contained in:
parent
71fa793480
commit
3ca662b591
@ -6,5 +6,6 @@ authors = ["candifloss <candifloss.cc>"]
|
||||
|
||||
[dependencies]
|
||||
zbus = "4.4.0"
|
||||
zbus_names = "*"
|
||||
# rson_rs = "0.2.1"
|
||||
tokio = "1.39.3"
|
66
src/main.rs
66
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<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),
|
||||
}
|
||||
}
|
||||
Err(e) => println!("Error receiving message: {:?}", e),
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
Ok(())
|
||||
}
|
||||
|
@ -130,3 +130,20 @@ fn truncate_summary(notif: &mut Notif) {
|
||||
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
|
||||
)?;
|
Loading…
Reference in New Issue
Block a user