diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..97fe5c73 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "rust-analyzer.linkedProjects": [ + "./odilia-notify/Cargo.toml" + ] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index bc870ac2..c4b80020 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2271,7 +2271,6 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2 0.5.6", diff --git a/Cargo.toml b/Cargo.toml index 826c991e..039a5d69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,12 @@ [workspace] -default-members = ["odilia"] +resolver="2" +default-members = ["odilia", "odilia-notify"] members = [ "cache", "common", "input", "odilia", -"odilia-notify", + "odilia-notify", ] [profile.release] @@ -40,6 +41,7 @@ odilia-cache = { version = "0.3.0", path = "./cache" } eyre = "0.6.8" nix = "0.26.2" serde_json = "1.0.89" +serde = { version = "1.0.194", features = ["derive"] } ssip-client-async = { default-features = false, features = ["tokio"], version = "0.10.0" } tokio = { version = "^1.22.0", default-features = false, features = ["sync", "macros", "rt", "signal", "tracing"] } tracing = "^0.1.37" @@ -47,6 +49,6 @@ tracing-log = "^0.1.3" tracing-subscriber = { version = "0.3.16", default-features = false, features = ["env-filter", "parking_lot"] } tracing-error = "^0.2.0" tracing-tree = "^0.2.2" -zbus = { version = "^3.6.2", default-features = false, features = ["tokio"] } +zbus = { version = "3.14.1", features = ["tokio"] } serde_plain = "1.0.1" diff --git a/odilia-notify/Cargo.toml b/odilia-notify/Cargo.toml index cc73351a..2edf1399 100644 --- a/odilia-notify/Cargo.toml +++ b/odilia-notify/Cargo.toml @@ -14,11 +14,10 @@ edition = "2021" [dependencies] futures = "0.3.30" -serde = { version = "1.0.194", features = ["derive"] } +serde.workspace=true thiserror = "1.0.56" -tokio = { version = "1.35.1", features = ["full"] } -tracing = "0.1.40" -zbus = { version = "3.14.1", features = ["tokio"] } - +tokio.workspace=true +tracing.workspace=true +zbus.workspace=true [dev-dependencies] notify-rust = "4.10.0" diff --git a/odilia-notify/src/notification.rs b/odilia-notify/src/notification.rs index af919dad..838cbce0 100644 --- a/odilia-notify/src/notification.rs +++ b/odilia-notify/src/notification.rs @@ -23,3 +23,43 @@ impl TryFrom> for Notification { Ok(Notification { app_name, title, body }) } } +#[cfg(test)] +mod tests { + use zbus::names::UniqueName; + + use super::*; + #[test] + fn correctly_formatted_message_leads_to_a_correct_notification() -> Result<(), zbus::Error> + { + // Simulate a method call to the org.freedesktop.notifications interface + let message = Message::method( + Some(":0.1"), //I can't pass none here, because of type needed errors, so passing dummy values for now + Some(":0.3"), //same here + "/org/freedesktop/notifications", + Some("org.freedesktop.notifications"), + "notify", + &( + "ExampleApp", + 0u32, + "summary", + "Test Title", + "Test Body", + Vec::<&str>::new(), + HashMap::<&str, Value>::new(), + 0, + ), + )?; + + //make this into an arc, to use the try_from implementation used in the wild + let message = Arc::new(message); + // Convert the Message into a Notification + let notification = Notification::try_from(message)?; + + // Assert that the conversion was successful and the fields are as expected + assert_eq!(notification.app_name, "ExampleApp"); + assert_eq!(notification.title, "Test Title"); + assert_eq!(notification.body, "Test Body"); + + Ok(()) + } +}