Initial notifications crate
This commit is contained in:
parent
d7323323f8
commit
756238feab
|
@ -2,6 +2,7 @@
|
|||
members = [
|
||||
"apps/magpie",
|
||||
"apps/music-player",
|
||||
"apps/notifications",
|
||||
"apps/sandbox",
|
||||
"crates/script",
|
||||
"scripts/music-player",
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "canary-notifications"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
smol = "1.2"
|
||||
zbus = "3.5"
|
|
@ -0,0 +1,72 @@
|
|||
use std::collections::HashMap;
|
||||
use std::future::pending;
|
||||
|
||||
use zbus::{dbus_interface, zvariant::Value, ConnectionBuilder, SignalContext};
|
||||
|
||||
pub struct Notifications {}
|
||||
|
||||
#[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 notifications = Notifications {};
|
||||
|
||||
let _ = ConnectionBuilder::session()
|
||||
.unwrap()
|
||||
.name("org.freedesktop.Notifications")
|
||||
.unwrap()
|
||||
.serve_at("/org/freedesktop/Notifications", notifications)
|
||||
.unwrap()
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
pending::<()>().await;
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue