This commit is contained in:
Candifloss 2024-09-17 02:58:58 +05:30
parent ff213fdd70
commit d4f2140f55
2 changed files with 9 additions and 4 deletions

View File

@ -4,6 +4,11 @@ use notification::{print_notif, to_notif};
use futures_util::stream::TryStreamExt; use futures_util::stream::TryStreamExt;
use zbus::{Connection, Result}; use zbus::{Connection, Result};
const SERVER_NAME: &str = "SNot";
const VENDOR: &str = "candifloss.cc";
const VERSION: &str = "0.1.0";
const SPEC_VERSION: &str = "0.1.0";
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let connection = Connection::session().await?; let connection = Connection::session().await?;
@ -20,9 +25,9 @@ async fn main() -> Result<()> {
match member_name { match member_name {
"GetServerInformation" => { "GetServerInformation" => {
// Respond with server information // Respond with server information
let response = ("SNot", "candifloss.cc", "0.1.0", "0.1.0"); // (name, vendor, version, spec_version) let response = (SERVER_NAME, VENDOR, VERSION, SPEC_VERSION); // (name, vendor, version, spec_version)
connection.reply(&msg, &response).await?; connection.reply(&msg, &response).await?;
println!("Request received: {member}\n\tName: SNot\n\tVendor: candifloss.cc\n\tVersion: 0.1.0\n\tSpec_version: 0.1.0"); println!("Request received: {member}\n\tName: {SERVER_NAME}\n\tVendor: {VENDOR}\n\tVersion: {VERSION}\n\tSpec_version: {SPEC_VERSION}");
} }
"GetCapabilities" => { "GetCapabilities" => {
// Respond with supported capabilities // Respond with supported capabilities
@ -38,7 +43,7 @@ async fn main() -> Result<()> {
let notif = to_notif(&msg_body)?; let notif = to_notif(&msg_body)?;
// Print the notif // Print the notif
print_notif(&notif); print_notif(&notif);
println!("{}", notif.urgency()); println!("{}\n", notif.urgency());
// Done. Respond to the client with a notification ID // Done. Respond to the client with a notification ID
let notification_id: u32 = 1; // This could be incremented or generated. Do it l8r let notification_id: u32 = 1; // This could be incremented or generated. Do it l8r
connection.reply(&msg, &notification_id).await?; // The client will disconnect when it gets this response connection.reply(&msg, &notification_id).await?; // The client will disconnect when it gets this response

View File

@ -56,5 +56,5 @@ pub fn print_notif(notif: &Notification) {
for (key, value) in &notif.hints { for (key, value) in &notif.hints {
println!(" {key}: {value:?}"); println!(" {key}: {value:?}");
} }
println!("Expiration Timeout: {0} seconds\n", notif.expir_timeout); println!("Expiration Timeout: {0} seconds", notif.expir_timeout);
} }