82 lines
2.2 KiB
Rust
82 lines
2.2 KiB
Rust
use std::collections::HashMap;
|
|
use std::future::pending;
|
|
|
|
use canary_magpie::protocol::*;
|
|
use smol::net::unix::UnixStream;
|
|
use zbus::{dbus_interface, zvariant::Value, ConnectionBuilder, SignalContext};
|
|
|
|
pub type MagpieClient = ClientMessenger<UnixStream>;
|
|
|
|
pub struct Notifications {
|
|
magpie: MagpieClient,
|
|
}
|
|
|
|
#[dbus_interface(name = "org.freedesktop.Notifications")]
|
|
impl Notifications {
|
|
fn get_capabilities(&self) -> Vec<String> {
|
|
vec!["body", "body-markup", "actions", "icon-static"]
|
|
.into_iter()
|
|
.map(ToString::to_string)
|
|
.collect()
|
|
}
|
|
|
|
#[dbus_interface(out_args("name", "vendor", "version", "spec_version"))]
|
|
fn get_server_information(&self) -> zbus::fdo::Result<(String, String, String, String)> {
|
|
Ok((
|
|
"canary-notifications".to_string(),
|
|
"Canary Development Team".to_string(),
|
|
"0.1.0".to_string(),
|
|
"1.2".to_string(),
|
|
))
|
|
}
|
|
|
|
fn notify(
|
|
&self,
|
|
app_name: String,
|
|
replaces_id: u32,
|
|
app_icon: String,
|
|
summary: String,
|
|
body: String,
|
|
actions: Vec<String>,
|
|
hints: HashMap<String, Value>,
|
|
expire_timeout: i32,
|
|
) -> u32 {
|
|
println!("{}: {}", summary, body);
|
|
0
|
|
}
|
|
|
|
fn close_notification(&self, id: u32) {}
|
|
|
|
#[dbus_interface(signal)]
|
|
async fn notification_closed(ctx: &SignalContext<'_>, id: u32, reason: u32)
|
|
-> zbus::Result<()>;
|
|
|
|
#[dbus_interface(signal)]
|
|
async fn action_invoked(
|
|
ctx: &SignalContext<'_>,
|
|
id: u32,
|
|
action_key: String,
|
|
) -> zbus::Result<()>;
|
|
}
|
|
|
|
pub fn main() {
|
|
smol::block_on(async {
|
|
let sock_path = find_socket();
|
|
let socket = UnixStream::connect(sock_path).await.unwrap();
|
|
let magpie = MagpieClient::new(socket);
|
|
let notifications = Notifications { magpie };
|
|
|
|
let _ = ConnectionBuilder::session()
|
|
.unwrap()
|
|
.name("org.freedesktop.Notifications")
|
|
.unwrap()
|
|
.serve_at("/org/freedesktop/Notifications", notifications)
|
|
.unwrap()
|
|
.build()
|
|
.await
|
|
.unwrap();
|
|
|
|
pending::<()>().await;
|
|
});
|
|
}
|