From fb42d4affd3c09cbb3f4f8a0a82f5e82666a440e Mon Sep 17 00:00:00 2001 From: candifloss Date: Sun, 15 Sep 2024 21:13:09 +0530 Subject: [PATCH] Some actual progress --- src/main.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index c8247d2..43bf87f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use zbus::{Connection, Result}; use futures_util::stream::TryStreamExt; +use zbus::{Connection, Result}; #[tokio::main] async fn main() -> Result<()> { @@ -8,25 +8,24 @@ async fn main() -> Result<()> { .request_name("org.freedesktop.Notifications") // Requesting dbus for this service name. Any other services using this name should be stopped/disabled before this .await?; - let mut stream = zbus::MessageStream::from(&connection); // Convert connection to a MessageStream, yields Message items + let mut stream = zbus::MessageStream::from(&connection); // Convert connection to a MessageStream, yields Message items 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; + // Check if the message is a method call to the "Notify" method + if let Some(member) = msg.header().member().map(|m| m.as_str()) { + if member == "GetServerInformation" { + println!("Member is: {}", member); + // Respond with server information + let response = ("SNot", "candifloss.cc", "0.1.0", "1.0"); // (name, vendor, version, spec_version) + connection.reply(&msg, &response).await?; + } else if member == "Notify" { + println!("Member is: {}", member); + // Respond with a notification ID (usually a unique number) + let notification_id: u32 = 1; // This could be incremented or generated + connection.reply(&msg, ¬ification_id).await?; + } else { + println!("Unhandled method: {}", member); } - _ => continue, } }