diff --git a/Cargo.lock b/Cargo.lock index 0ca0962..92ab863 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,6 +247,8 @@ name = "fldsmdfr" version = "0.1.0" dependencies = [ "clap", + "serde", + "serde_json", "tokio", "zbus", ] @@ -378,6 +380,12 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "itoa" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" + [[package]] name = "lazy_static" version = "1.4.0" @@ -662,6 +670,12 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "ryu" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" + [[package]] name = "scopeguard" version = "1.1.0" @@ -688,6 +702,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "serde_repr" version = "0.1.10" diff --git a/Cargo.toml b/Cargo.toml index 160309e..0a86b4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,5 +5,7 @@ edition = "2021" [dependencies] clap = { version = "4.1.8", features = ["derive"] } +serde = "1.0.152" +serde_json = "1.0.93" tokio = { version = "1", features = ["full"] } zbus = { version = "3", default-features = false, features = ["tokio"]} diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..d875f98 --- /dev/null +++ b/src/client.rs @@ -0,0 +1,18 @@ +use std::error::Error; +use zbus::{dbus_proxy, Connection}; + +#[dbus_proxy( + default_service = "org.freedesktop.Notifications", + interface = "org.freedesktop.Notifications", + default_path = "/org/freedesktop/Notifications" +)] +trait Manager { + fn list(&self, short: bool) -> zbus::Result; +} + +pub async fn list(short: bool) -> Result<(), Box> { + let connection = Connection::session().await?; + let proxy = ManagerProxy::new(&connection).await?; + println!("{}", proxy.list(short).await?); + Ok(()) +} diff --git a/src/daemon.rs b/src/daemon.rs index dff11ff..9b04943 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -1,9 +1,9 @@ use crate::notification::Hints; +use crate::notification::Notification; use std::collections::HashMap; use std::error::Error; use zbus::dbus_interface; use zbus::Connection; -use crate::notification::Notification; pub struct NotifyManager { next_id: u32, @@ -84,4 +84,13 @@ impl NotifyManager { "1.2", ] } + + fn list(&self, short: bool) -> String { + if short { + unreachable!() + // self.pendings.values().map(|x| x.summary).join("\n") + } else { + serde_json::to_string(&self.pendings).unwrap() + } + } } diff --git a/src/main.rs b/src/main.rs index d04d84a..4d56329 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ mod daemon; mod notification; +mod client; use clap::{Parser, Subcommand}; use daemon::NotifyManager; @@ -27,14 +28,22 @@ enum Command { #[arg(short, long)] clear: bool, }, + + /// List pending notifications + List { + /// Use a quick overview instead of json, one notification per line + #[arg(short, long)] + short: bool, + }, } #[tokio::main] async fn main() -> Result<(), Box> { let cli = Args::parse(); - match &cli.command { + match cli.command { Command::Daemon => NotifyManager::new().start().await, + Command::List { short } => client::list(short).await, Command::Listen { .. } => unimplemented!(), } } diff --git a/src/notification.rs b/src/notification.rs index bbdf204..958f4d2 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -1,5 +1,7 @@ use zbus::zvariant::{DeserializeDict, SerializeDict, Type}; +use serde::Serialize; +#[derive(Serialize)] pub struct Notification { pub app_name: String, pub app_icon: String,