Skip to content

Commit

Permalink
Merge commit '7cbc88d1655f1668f431662dc334e262e93f4853' into notify
Browse files Browse the repository at this point in the history
merge a pull request for odilia-notify and reflect it here as well
  • Loading branch information
albertotirla committed Jan 20, 2024
2 parents d36f4da + 7cbc88d commit b4ce9f2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
6 changes: 2 additions & 4 deletions odilia-notify/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use futures::{Stream, StreamExt};
use std::{ops::Deref, sync::Arc};
use tracing::{debug, info, instrument};

use zbus::{fdo::MonitoringProxy, Connection, MatchRule, MessageStream, MessageType};
Expand Down Expand Up @@ -30,11 +29,10 @@ pub async fn listen_to_dbus_notifications() -> Result<impl Stream<Item = Notific
debug!(?notify_rule, "finished generating rule");
info!("listening for notifications");

Check warning on line 30 in odilia-notify/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/lib.rs#L29-L30

Added lines #L29 - L30 were not covered by tests
let notify_rule = notify_rule.to_string();
monitor.become_monitor(&[notify_rule.deref()], 0).await?;
monitor.become_monitor(&[notify_rule.as_str()], 0).await?;

let stream = MessageStream::from(monitor.connection()).filter_map(move |message| async {
let message = Arc::into_inner(message.ok()?)?; // Extract the Message from the Arc, I'm not sure whether this will work or not. Todo: try to find a better way of doing this
let notification = message.try_into().ok()?;
let notification = message.ok()?.try_into().ok()?;
debug!(?notification, "adding notification to stream");
Some(notification)
});

Check warning on line 38 in odilia-notify/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/lib.rs#L34-L38

Added lines #L34 - L38 were not covered by tests
Expand Down
50 changes: 25 additions & 25 deletions odilia-notify/src/notification.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use zbus::{zvariant::Value, Message};

#[derive(Debug, Serialize, Deserialize)]
pub struct Notification {
pub app_name: String,
pub title: String,
pub body: String,
}

type MessageBody<'a> =
(String, u32, &'a str, String, String, Vec<&'a str>, HashMap<&'a str, Value<'a>>, i32);

impl TryFrom<Message> for Notification {
type Error = zbus::Error;

fn try_from(value: Message) -> Result<Self, Self::Error> {
let (app_name, _, _, title, body, ..) = value.body::<MessageBody>()?;

Ok(Notification { app_name, title, body })
}
}
use std::{collections::HashMap, sync::Arc};

use serde::{Deserialize, Serialize};

use zbus::{zvariant::Value, Message};

#[derive(Debug, Serialize, Deserialize)]

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

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/notification.rs#L7

Added line #L7 was not covered by tests
pub struct Notification {
pub app_name: String,
pub title: String,
pub body: String,
}

type MessageBody<'a> =
(String, u32, &'a str, String, String, Vec<&'a str>, HashMap<&'a str, Value<'a>>, i32);

impl TryFrom<Arc<Message>> for Notification {
type Error = zbus::Error;

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

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

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/notification.rs#L20-L21

Added lines #L20 - L21 were not covered by tests

Ok(Notification { app_name, title, body })
}

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

View check run for this annotation

Codecov / codecov/patch

odilia-notify/src/notification.rs#L23-L24

Added lines #L23 - L24 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn test_listen_to_dbus_notifications() -> Result<(), Box<dyn Error>> {
// Delay sending the notification
tokio::time::sleep(Duration::from_secs(1)).await;

// Send a Notification to see if it's correctly recieved on the other side
// Send a Notification to see if it's correctly received on the other side
Notification::new()
.appname("test-notify")
.summary("test summary")
Expand Down

0 comments on commit b4ce9f2

Please sign in to comment.