Adding required methods

This commit is contained in:
2023-03-02 15:31:31 +09:00
parent f3b8acd495
commit 571e3927c1
2 changed files with 35 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ pkgs.mkShell {
cargo
rustfmt
rustc
libnotify
];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";

View File

@@ -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<String>,
urgency: Option<u8>,
}
#[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<dyn Error>> {
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 {}
}