Compare commits
2 Commits
007786d3fb
...
cbfc072966
Author | SHA1 | Date | |
---|---|---|---|
cbfc072966 | |||
5e1e98b816 |
@ -2,10 +2,8 @@
|
|||||||
name = "snot"
|
name = "snot"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
authors = ["candifloss <candifloss.cc>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
zbus = "4.4.0"
|
dbus = "0.9.7"
|
||||||
rson_rs = "0.2.1"
|
rson_rs = "0.2.1"
|
||||||
tokio = {version = "^1.39.2", features = ["full"] }
|
|
||||||
futures = "0.3"
|
|
||||||
futures-util = "0.3"
|
|
59
src/main.rs
59
src/main.rs
@ -1,39 +1,32 @@
|
|||||||
use zbus::{Connection, MessageStream, MatchRule, fdo};
|
struct Notif {
|
||||||
use zbus::zvariant::{OwnedValue, Type};
|
app_name: String,
|
||||||
|
replace_id: u32,
|
||||||
#[derive(Debug)]
|
ico: String, //It's string, right?
|
||||||
struct Notification {
|
summary: String,
|
||||||
// ... fields
|
body: String,
|
||||||
//
|
//Actions
|
||||||
|
//Hints
|
||||||
|
expir_timeout: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
// Summary should be generally <= 40 chars, as per the specification.
|
||||||
async fn main() -> Result<(), zbus::Error> {
|
fn truncate_summary(notif: &mut Notif) {
|
||||||
let conn = Connection::new_session()?;
|
if notif.summary.len() > 40 {
|
||||||
|
notif.summary.truncate(39);
|
||||||
|
notif.summary.push_str("…");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create a match rule to filter for notification signals
|
fn main() {
|
||||||
let match_rule = MatchRule::new_signal()
|
let mut not = Notif {
|
||||||
.interface("org.freedesktop.Notifications")
|
app_name: "snot".to_string(),
|
||||||
.member("Notify")
|
replace_id: 0,
|
||||||
.build()?;
|
ico: "alert".to_string(),
|
||||||
|
summary: "This is a very long suuummmaaarrryyy! Don't you believe me????".to_string(),
|
||||||
// Add the match rule to the connection
|
body: "short body(hehe)".to_string(),
|
||||||
conn.add_match(&match_rule)?;
|
expir_timeout: 0
|
||||||
|
|
||||||
let stream = MessageStream::new(&conn)?;
|
|
||||||
|
|
||||||
while let Some(msg) = stream.next().await? {
|
|
||||||
// Extract notification data from the message
|
|
||||||
// ...
|
|
||||||
|
|
||||||
// Create a Notification struct
|
|
||||||
let notification = Notification {
|
|
||||||
// ...
|
|
||||||
};
|
};
|
||||||
|
truncate_summary(&mut not); //Limit the summary length
|
||||||
|
|
||||||
// Handle the notification
|
println!("{}",not.summary);
|
||||||
println!("Received notification: {:?}", notification);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user