failed experiments

This commit is contained in:
Candifloss 2024-09-14 16:03:40 +05:30
parent 8bbdc51523
commit 2d32e1612e

View File

@ -1,20 +1,33 @@
use zbus::{Connection, Result};
use futures_util::stream::TryStreamExt;
use zbus::{Connection, MessageStream, Result};
use zvariant::{Type, Value};
#[tokio::main]
async fn main() -> Result<()> {
let connection = Connection::session().await?;
connection
.request_name("org.freedesktop.Notifications") // Requesting dbus for this service name
.request_name("org.freedesktop.Notifications") // Requesting dbus for this service name. Any other services using this name should be stopped/disabled before this
.await?;
// Process incoming notifs
use futures_util::stream::TryStreamExt;
let mut stream = zbus::MessageStream::from(&connection); // Convert connection to a MessageStream, yields Message items
let mut stream = zbus::MessageStream::from(&connection); // Convert the connection into a message stream
while let Some(msg) = stream.try_next().await? {
///
println!("{}", msg);
let msg_header = msg.header();
dbg!(&msg);
match msg_header.message_type() {
zbus::message::Type::MethodCall => {
// real code would check msg_header path(), interface() and member()
// handle invalid calls, introspection, errors etc
let body = msg.body();
let arg: &str = body.deserialize()?;
println!("{}", arg);
connection.reply(&msg, &(format!("Hello {}!", arg))).await?;
// break;
}
_ => continue,
}
}
Ok(())