From 2d32e1612e7efd6dcac7cee82840ccf9f7fb7423 Mon Sep 17 00:00:00 2001 From: candifloss Date: Sat, 14 Sep 2024 16:03:40 +0530 Subject: [PATCH] failed experiments --- src/main.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 83db161..c8247d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(())