Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification improvements #135

Merged
merged 7 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions odilia-notify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions odilia-notify/src/action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]

Check warning on line 3 in odilia-notify/src/action.rs

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/action.rs#L3

Added line #L3 was not covered by tests
pub struct Action {
pub name: String,
pub method: String,
}
2 changes: 2 additions & 0 deletions odilia-notify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 24 additions & 3 deletions odilia-notify/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

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)]

Check warning on line 11 in odilia-notify/src/notification.rs

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/notification.rs#L11

Added line #L11 was not covered by tests
pub struct Notification {
pub app_name: String,
pub title: String,
pub body: String,
pub urgency: Urgency,
pub actions: Vec<Action>,
}

type MessageBody<'a> =
Expand All @@ -18,9 +24,24 @@
type Error = zbus::Error;

fn try_from(msg: Arc<Message>) -> Result<Self, Self::Error> {
let (app_name, _, _, title, body, ..) = msg.body::<MessageBody>()?;
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(),

Check warning on line 34 in odilia-notify/src/notification.rs

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/notification.rs#L33-L34

Added lines #L33 - L34 were not covered by tests
})
.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)]
Expand Down
28 changes: 28 additions & 0 deletions odilia-notify/src/urgency.rs
Original file line number Diff line number Diff line change
@@ -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,

Check warning on line 7 in odilia-notify/src/urgency.rs

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/urgency.rs#L7

Added line #L7 was not covered by tests
Copy,
Debug,
Type,
Serialize,
Deserialize,
Default,
Value,
OwnedValue,

Check warning on line 15 in odilia-notify/src/urgency.rs

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/urgency.rs#L9-L15

Added lines #L9 - L15 were not covered by tests
Eq,
PartialEq,
PartialOrd,
Ord,

Check warning on line 19 in odilia-notify/src/urgency.rs

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/urgency.rs#L17-L19

Added lines #L17 - L19 were not covered by tests
)]
#[zvariant(signature = "y")]
#[repr(u8)]
pub enum Urgency {
Low = 0,
#[default]
Normal = 1,
Critical = 2,
}
Loading