From 571e3927c13bb0d55f0fc0ff29cf5cc507a145e5 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 2 Mar 2023 15:31:31 +0900 Subject: [PATCH] Adding required methods --- shell.nix | 1 + src/main.rs | 44 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/shell.nix b/shell.nix index 7785c86..10fd0ad 100644 --- a/shell.nix +++ b/shell.nix @@ -4,6 +4,7 @@ pkgs.mkShell { cargo rustfmt rustc + libnotify ]; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; diff --git a/src/main.rs b/src/main.rs index 4cd3166..234966d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,18 @@ -use std::{error::Error, future::pending}; -use zbus::{dbus_interface, ConnectionBuilder}; +use std::error::Error; +use zbus::{Connection, zvariant::{DeserializeDict, SerializeDict, Type}}; +use zbus::dbus_interface; struct NotifManager { next_id: u32, } +#[derive(DeserializeDict, SerializeDict, Type)] +#[zvariant(signature = "dict")] +struct Hints { + category: Option, + urgency: Option, +} + #[dbus_interface(name = "org.freedesktop.Notifications")] impl NotifManager { fn notify( @@ -14,25 +22,41 @@ impl NotifManager { app_icon: &str, summary: &str, body: &str, - // actions: as, - // hints: a{sv}, + actions: Vec<&str>, + hints: Hints, expire_timeout: i32, ) -> u32 { self.next_id += 1; println!("{}: {}", summary, body); self.next_id } + + fn get_capabilities(&self) -> Vec<&str> { + vec!["body", "actions", "body-images", "persistence", "icon-static"] + } + + fn get_server_information(&self) -> [&str; 4] { + [ + env!("CARGO_PKG_NAME"), + "zoriya", + env!("CARGO_PKG_VERSION"), + "1.2", + ] + } } #[tokio::main] async fn main() -> Result<(), Box> { + let connection = Connection::session().await?; let manager = NotifManager { next_id: 0 }; - let _ = ConnectionBuilder::session()? - .name("org.freedesktop.Notifications")? - .serve_at("/org/freedesktop/Notifications", manager)? - .build() + + connection + .object_server() + .at("/org/freedesktop/Notifications", manager) + .await?; + connection + .request_name("org.freedesktop.Notifications") .await?; - pending::<()>().await; - Ok(()) + loop {} }