diff --git a/Cargo.toml b/Cargo.toml index fe26c3e..f1a880c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ authors = ["candifloss "] [dependencies] zbus = "4.4.0" # rson_rs = "0.2.1" +tokio = "1.39.3" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a87009a..de1f886 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,24 @@ -use zbus::blocking::Connection; +//use zbus::blocking::Connection; +use zbus::Connection; use zbus::fdo::Result; use zbus::Message; use zbus::MatchRule; +use zbus::blocking::Proxy; +use zbus::MessageStream; +//use futures_util::stream::TryStreamExt; fn main() -> Result<()> { // Establish a connection to the session bus let connection = Connection::session()?; + // Proxy + let prox = Proxy::new( + &connection, + "org.freedesktop.Notifications", // Service/Bus name + "/org/freedesktop/Notifications", // Object path + "org.freedesktop.Notifications", // Interface name + )?; + // Define a match rule for the notifications let match_rule = MatchRule::builder() .msg_type(zbus::MessageType::Signal) @@ -15,15 +27,22 @@ fn main() -> Result<()> { .build(); // Add the match rule to the connection - connection.add_match(match_rule)?; + //connection.add_match(match_rule)?; + let mut stream = MessageStream::from(connection); + while let Some(msg) = stream.body? { + println!("Got message: {}", msg); + } // Process notifications - loop { - let message = connection.receive_message()?; + /*loop { + /* + let message = connection.receive_signal()?; if let Some(member) = message.member() { if member.as_str() == "Notify" { println!("Received a notification: {:?}", message); } - } - } + } */ + + }*/ + Ok(()) } diff --git a/src/notif.xml b/src/notif.xml new file mode 100644 index 0000000..a9fa1e6 --- /dev/null +++ b/src/notif.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/notifications.rs b/src/notifications.rs new file mode 100644 index 0000000..8fc9d3b --- /dev/null +++ b/src/notifications.rs @@ -0,0 +1,59 @@ +//! # D-Bus interface proxy for: `org.freedesktop.Notifications` +//! +//! This code was generated by `zbus-xmlgen` `4.1.0` from D-Bus introspection data. +//! Source: `notif.xml`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the [Writing a client proxy] section of the zbus +//! documentation. +//! +//! This type implements the [D-Bus standard interfaces], (`org.freedesktop.DBus.*`) for which the +//! following zbus API can be used: +//! +//! * [`zbus::fdo::PropertiesProxy`] +//! * [`zbus::fdo::IntrospectableProxy`] +//! * [`zbus::fdo::PeerProxy`] +//! +//! Consequently `zbus-xmlgen` did not generate code for the above interfaces. +//! +//! [Writing a client proxy]: https://dbus2.github.io/zbus/client.html +//! [D-Bus standard interfaces]: https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces, +use zbus::proxy; +#[proxy(interface = "org.freedesktop.Notifications", assume_defaults = true)] +trait Notifications { + /// CloseNotification method + fn close_notification(&self, arg_0: u32) -> zbus::Result<()>; + + /// GetCapabilities method + fn get_capabilities(&self) -> zbus::Result>; + + /// GetServerInformation method + fn get_server_information(&self) -> zbus::Result<(String, String, String, String)>; + + /// Notify method + #[allow(clippy::too_many_arguments)] + fn notify( + &self, + arg_0: &str, + arg_1: u32, + arg_2: &str, + arg_3: &str, + arg_4: &str, + arg_5: &[&str], + arg_6: std::collections::HashMap<&str, &zbus::zvariant::Value<'_>>, + arg_7: i32, + ) -> zbus::Result; + + /// ActionInvoked signal + #[zbus(signal)] + fn action_invoked(&self, arg_0: u32, arg_1: &str) -> zbus::Result<()>; + + /// ActivationToken signal + #[zbus(signal)] + fn activation_token(&self, arg_0: u32, arg_1: &str) -> zbus::Result<()>; + + /// NotificationClosed signal + #[zbus(signal)] + fn notification_closed(&self, arg_0: u32, arg_1: u32) -> zbus::Result<()>; +}