It started working!
This commit is contained in:
parent
fb42d4affd
commit
903647c8df
66
src/main.rs
66
src/main.rs
@ -1,5 +1,35 @@
|
|||||||
use futures_util::stream::TryStreamExt;
|
use futures_util::stream::TryStreamExt;
|
||||||
use zbus::{Connection, Result};
|
use std::collections::HashMap;
|
||||||
|
use zbus::{message::Body, Connection, Result};
|
||||||
|
use zvariant::OwnedValue;
|
||||||
|
|
||||||
|
fn print_notif(msg_body: Body) -> Result<()> {
|
||||||
|
// Deserialize the message body to the expected tuple
|
||||||
|
let (app_name, replace_id, icon, summary, body, actions, hints, expir_timeout): (
|
||||||
|
String,
|
||||||
|
u32,
|
||||||
|
String,
|
||||||
|
String,
|
||||||
|
String,
|
||||||
|
Vec<String>,
|
||||||
|
HashMap<String, OwnedValue>,
|
||||||
|
i32,
|
||||||
|
) = msg_body.deserialize()?;
|
||||||
|
// Print the notification details
|
||||||
|
println!("App Name: {app_name}");
|
||||||
|
println!("Replace ID: {replace_id}");
|
||||||
|
println!("Icon: {icon}");
|
||||||
|
println!("Summary: {summary}");
|
||||||
|
println!("Body: {body}");
|
||||||
|
println!("Actions: {actions:?}");
|
||||||
|
println!("Hints:");
|
||||||
|
for (key, value) in hints {
|
||||||
|
println!(" {key}: {value:?}");
|
||||||
|
}
|
||||||
|
println!("Expiration Timeout: {expir_timeout} seconds");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@ -13,19 +43,27 @@ async fn main() -> Result<()> {
|
|||||||
while let Some(msg) = stream.try_next().await? {
|
while let Some(msg) = stream.try_next().await? {
|
||||||
// Check if the message is a method call to the "Notify" method
|
// 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 let Some(member) = msg.header().member().map(|m| m.as_str()) {
|
||||||
if member == "GetServerInformation" {
|
match member {
|
||||||
println!("Member is: {}", member);
|
"GetServerInformation" => {
|
||||||
// Respond with server information
|
println!("Member is: {member}");
|
||||||
let response = ("SNot", "candifloss.cc", "0.1.0", "1.0"); // (name, vendor, version, spec_version)
|
// Respond with server information
|
||||||
connection.reply(&msg, &response).await?;
|
let response = ("SNot", "candifloss.cc", "0.1.0", "1.0"); // (name, vendor, version, spec_version)
|
||||||
} else if member == "Notify" {
|
connection.reply(&msg, &response).await?;
|
||||||
println!("Member is: {}", member);
|
}
|
||||||
// Respond with a notification ID (usually a unique number)
|
"Notify" => {
|
||||||
let notification_id: u32 = 1; // This could be incremented or generated
|
println!("Member is: {member}");
|
||||||
connection.reply(&msg, ¬ification_id).await?;
|
// Handle notif
|
||||||
} else {
|
let msg_body = msg.body();
|
||||||
println!("Unhandled method: {}", member);
|
// get the app_name, summary, body, etc. from the msg_body and print it
|
||||||
}
|
let _ = print_notif(msg_body);
|
||||||
|
// Done. Respond with a notification ID
|
||||||
|
let notification_id: u32 = 1; // This could be incremented or generated
|
||||||
|
connection.reply(&msg, ¬ification_id).await?;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("Unhandled method: {member}");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user