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