mod notification; use notification::to_notif; use futures_util::stream::TryStreamExt; use zbus::{Connection, Result}; const SERVER_NAME: &str = "SNot"; // Server software name const VENDOR: &str = "candifloss.cc"; // Server sw author const VERSION: &str = "0.1.0"; // Server version const SPEC_VERSION: &str = "0.42"; // DBus Spec version #[tokio::main] async fn main() -> Result<()> { let connection = Connection::session().await?; connection .request_name("org.freedesktop.Notifications") // Requesting dbus for this service name. Any other services/progs 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 while let Some(msg) = stream.try_next().await? { // Check if the message is a method call to the "Notify" method if let Some(member) = msg.header().member() { let member_name = member.as_str(); match member_name { "GetServerInformation" => { // Respond with server information: (name, vendor, version, dbus_spec_version) let response = (SERVER_NAME, VENDOR, VERSION, SPEC_VERSION); connection.reply(&msg, &response).await?; println!("Request received: {member}\n\tName: {SERVER_NAME}, Vendor: {VENDOR}, Version: {VERSION}, DBus spec version: {SPEC_VERSION}"); // Remove this later } "GetCapabilities" => { // Respond with supported capabilities let capabilities = vec!["actions", "body", "body-hyperlinks"]; connection.reply(&msg, &capabilities).await?; println!("Request received: {member}\n\tCapabilities: {capabilities:?}"); // Remove this later } "Notify" => { // Handle new received notif println!("New notification!"); let msg_body = msg.body(); // get the app_name, summary, body, etc. from the msg_body let notif = to_notif(&msg_body)?; // Print the notif //print_notif(¬if); println!("{}", ¬if.plain()); // Done. Respond to the client with a notification ID let notification_id: u32 = 1; // This could be incremented or generated. Do it l8r connection.reply(&msg, ¬ification_id).await?; // The client will disconnect when it gets this response } _ => { println!("Unhandled method: {member}"); // Other methods are irrelevant or not handled at this stage of development } } } } Ok(()) }