SNot/src/main.rs

34 lines
1.4 KiB
Rust
Raw Normal View History

2024-09-01 08:20:17 +00:00
use futures_util::stream::TryStreamExt;
2024-09-15 15:43:09 +00:00
use zbus::{Connection, Result};
2024-08-27 11:28:05 +00:00
#[tokio::main]
async fn main() -> Result<()> {
let connection = Connection::session().await?;
2024-09-01 08:20:17 +00:00
connection
2024-09-14 10:33:40 +00:00
.request_name("org.freedesktop.Notifications") // Requesting dbus for this service name. Any other services using this name should be stopped/disabled before this
2024-09-01 08:20:17 +00:00
.await?;
2024-08-25 21:10:15 +00:00
2024-09-15 15:43:09 +00:00
let mut stream = zbus::MessageStream::from(&connection); // Convert connection to a MessageStream, yields Message items
2024-09-01 11:31:19 +00:00
while let Some(msg) = stream.try_next().await? {
2024-09-15 15:43:09 +00:00
// 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, &notification_id).await?;
} else {
println!("Unhandled method: {}", member);
2024-09-14 10:33:40 +00:00
}
}
2024-09-01 11:31:19 +00:00
}
Ok(())
}