diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd7e0845..33b817fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -173,7 +173,7 @@ jobs: systemctl --user start dbus; xvfb-run dunst --screen 0 600x400x8 & - name: cargo llvm-cov - run: cargo llvm-cov --locked --lcov --output-path lcov.info + run: cargo llvm-cov --lcov --output-path lcov.info - name: Upload to codecov.io uses: codecov/codecov-action@v3 with: diff --git a/Cargo.lock b/Cargo.lock index c4b80020..08586c3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -663,7 +663,7 @@ dependencies = [ "clap 3.2.25", "criterion-plot", "futures", - "itertools", + "itertools 0.10.5", "lazy_static", "num-traits", "oorandom", @@ -685,7 +685,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", - "itertools", + "itertools 0.10.5", ] [[package]] @@ -1209,6 +1209,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.10" @@ -1561,8 +1570,10 @@ name = "odilia-notify" version = "0.1.0" dependencies = [ "futures", + "itertools 0.12.1", "notify-rust", "serde", + "serde_repr", "thiserror", "tokio", "tracing", diff --git a/odilia-notify/Cargo.toml b/odilia-notify/Cargo.toml index 2edf1399..bdfbb06e 100644 --- a/odilia-notify/Cargo.toml +++ b/odilia-notify/Cargo.toml @@ -14,7 +14,9 @@ edition = "2021" [dependencies] futures = "0.3.30" +itertools = "0.12.1" serde.workspace=true +serde_repr = "0.1.18" thiserror = "1.0.56" tokio.workspace=true tracing.workspace=true diff --git a/odilia-notify/src/action.rs b/odilia-notify/src/action.rs new file mode 100644 index 00000000..560fe0bf --- /dev/null +++ b/odilia-notify/src/action.rs @@ -0,0 +1,7 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct Action { + pub name: String, + pub method: String, +} diff --git a/odilia-notify/src/lib.rs b/odilia-notify/src/lib.rs index 000f3a61..f9a3d034 100644 --- a/odilia-notify/src/lib.rs +++ b/odilia-notify/src/lib.rs @@ -2,7 +2,9 @@ use futures::{Stream, StreamExt}; use tracing::{debug, info, instrument}; use zbus::{fdo::MonitoringProxy, Connection, MatchRule, MessageStream, MessageType}; +mod action; mod notification; +mod urgency; use notification::Notification; mod error; use error::NotifyError; diff --git a/odilia-notify/src/notification.rs b/odilia-notify/src/notification.rs index 3dc918e0..2b6a0282 100644 --- a/odilia-notify/src/notification.rs +++ b/odilia-notify/src/notification.rs @@ -4,11 +4,17 @@ use serde::{Deserialize, Serialize}; use zbus::{zvariant::Value, Message}; -#[derive(Debug, Serialize, Deserialize)] +use crate::action::Action; +use crate::urgency::Urgency; +use itertools::Itertools; + +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct Notification { pub app_name: String, pub title: String, pub body: String, + pub urgency: Urgency, + pub actions: Vec, } type MessageBody<'a> = @@ -18,9 +24,24 @@ impl TryFrom> for Notification { type Error = zbus::Error; fn try_from(msg: Arc) -> Result { - let (app_name, _, _, title, body, ..) = msg.body::()?; + let mb: MessageBody = msg.body()?; + let (app_name, _, _, title, body, actions, mut options, _) = mb; + let actions = actions + .iter() + .tuples() + .map(|(name, method)| Action { + name: name.to_string(), + method: method.to_string(), + }) + .collect(); + // any error in deserailizing the value (including lack of "urgency" key in options + // hashmap) will give it an urgency of Normal + let urgency = options + .remove("urgency") + .and_then(|o| o.try_into().ok()) + .unwrap_or(Urgency::Normal); - Ok(Notification { app_name, title, body }) + Ok(Notification { app_name, title, body, actions, urgency }) } } #[cfg(test)] diff --git a/odilia-notify/src/urgency.rs b/odilia-notify/src/urgency.rs new file mode 100644 index 00000000..7924a37e --- /dev/null +++ b/odilia-notify/src/urgency.rs @@ -0,0 +1,28 @@ +use serde::{Deserialize, Serialize}; +use zbus::zvariant::{OwnedValue, Type, Value}; + +/// A priority/urgency level. +/// https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html#urgency-levels +#[derive( + Clone, + Copy, + Debug, + Type, + Serialize, + Deserialize, + Default, + Value, + OwnedValue, + Eq, + PartialEq, + PartialOrd, + Ord, +)] +#[zvariant(signature = "y")] +#[repr(u8)] +pub enum Urgency { + Low = 0, + #[default] + Normal = 1, + Critical = 2, +}