From 5e1e98b8166e76848839899c36acfb1f04eca730 Mon Sep 17 00:00:00 2001 From: candifloss Date: Sun, 11 Aug 2024 17:01:05 +0530 Subject: [PATCH] Finally started actually working on it --- Cargo.toml | 6 ++--- src/main.rs | 63 ++++++++++++++++++++++++----------------------------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d6d0bcf..a460878 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,10 +2,8 @@ name = "snot" version = "0.1.0" edition = "2021" +authors = ["candifloss "] [dependencies] -zbus = "4.4.0" +dbus = "0.9.7" rson_rs = "0.2.1" -tokio = {version = "^1.39.2", features = ["full"] } -futures = "0.3" -futures-util = "0.3" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e06c550..7108941 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,39 +1,32 @@ -use zbus::{Connection, MessageStream, MatchRule, fdo}; -use zbus::zvariant::{OwnedValue, Type}; - -#[derive(Debug)] -struct Notification { - // ... fields - // +struct Notif { + app_name: String, + replace_id: u32, + ico: String, //It's string, right? + summary: String, + body: String, + //Actions + //Hints + expir_timeout: i32, } -#[tokio::main] -async fn main() -> Result<(), zbus::Error> { - let conn = Connection::new_session()?; - - // Create a match rule to filter for notification signals - let match_rule = MatchRule::new_signal() - .interface("org.freedesktop.Notifications") - .member("Notify") - .build()?; - - // Add the match rule to the connection - conn.add_match(&match_rule)?; - - let stream = MessageStream::new(&conn)?; - - while let Some(msg) = stream.next().await? { - // Extract notification data from the message - // ... - - // Create a Notification struct - let notification = Notification { - // ... - }; - - // Handle the notification - println!("Received notification: {:?}", notification); +// Summary should be generally <= 40 chars, as per the specification. +fn truncate_summary(notif: &mut Notif) { + if notif.summary.len() > 40 { + notif.summary.truncate(39); + notif.summary.push_str("…"); } - - Ok(()) +} + +fn main() { + let mut not = Notif { + app_name: "snot".to_string(), + replace_id: 0, + ico: "alert".to_string(), + summary: "This is a very long suuummmaaarrryyy! Don't you believe me????".to_string(), + body: "short body(hehe)".to_string(), + expir_timeout: 0 + }; + truncate_summary(&mut not); + + println!("{}",not.summary); }