Compare commits
No commits in common. "e395fc92896ffe8e5df43295fd53b5656885162f" and "d4f2140f556e240c802dfe174cee128885b09f04" have entirely different histories.
e395fc9289
...
d4f2140f55
@ -7,7 +7,7 @@ use zbus::{Connection, Result};
|
|||||||
const SERVER_NAME: &str = "SNot";
|
const SERVER_NAME: &str = "SNot";
|
||||||
const VENDOR: &str = "candifloss.cc";
|
const VENDOR: &str = "candifloss.cc";
|
||||||
const VERSION: &str = "0.1.0";
|
const VERSION: &str = "0.1.0";
|
||||||
const SPEC_VERSION: &str = "1.0";
|
const SPEC_VERSION: &str = "0.1.0";
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@ -27,7 +27,7 @@ async fn main() -> Result<()> {
|
|||||||
// Respond with server information
|
// Respond with server information
|
||||||
let response = (SERVER_NAME, VENDOR, VERSION, SPEC_VERSION); // (name, vendor, version, spec_version)
|
let response = (SERVER_NAME, VENDOR, VERSION, SPEC_VERSION); // (name, vendor, version, spec_version)
|
||||||
connection.reply(&msg, &response).await?;
|
connection.reply(&msg, &response).await?;
|
||||||
println!("Request received: {member}\n\tName: {SERVER_NAME},\tVendor: {VENDOR},\tVersion: {VERSION},\tSpec_version: {SPEC_VERSION}");
|
println!("Request received: {member}\n\tName: {SERVER_NAME}\n\tVendor: {VENDOR}\n\tVersion: {VERSION}\n\tSpec_version: {SPEC_VERSION}");
|
||||||
}
|
}
|
||||||
"GetCapabilities" => {
|
"GetCapabilities" => {
|
||||||
// Respond with supported capabilities
|
// Respond with supported capabilities
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
use std::collections::{btree_map::Range, HashMap};
|
use std::collections::HashMap;
|
||||||
use zbus::{message::Body, Result};
|
use zbus::{message::Body, Result};
|
||||||
use zvariant::OwnedValue;
|
use zvariant::OwnedValue;
|
||||||
|
|
||||||
pub struct Notification {
|
pub struct Notification {
|
||||||
// A notificaion object
|
app_name: String,
|
||||||
app_name: String, // The application that sent the notification
|
replace_id: u32,
|
||||||
replace_id: u32, // (Optional) ID of an existing notification to be updated, replaced by this
|
icon: String,
|
||||||
icon: String, // See icon specifications: https://specifications.freedesktop.org/notification-spec/latest/icons-and-images.html
|
summary: String,
|
||||||
summary: String, // Notification title
|
body: String,
|
||||||
body: String, // Notification content/body
|
actions: Vec<String>,
|
||||||
actions: Vec<String>, // Action requests that can be sent back to the client -
|
hints: HashMap<String, OwnedValue>,
|
||||||
hints: HashMap<String, OwnedValue>, // Extra useful data - notif type, urgency, sound file, icon data, etc.
|
expir_timeout: i32,
|
||||||
expir_timeout: i32, // Seconds till this notif expires. Optional
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Notification {
|
impl Notification {
|
||||||
pub fn urgency(&self) -> String {
|
pub fn urgency(&self) -> String {
|
||||||
// Obtain urgency
|
|
||||||
match self.hints.get("urgency") {
|
match self.hints.get("urgency") {
|
||||||
Some(value) => {
|
Some(value) => {
|
||||||
// Attempt to convert OwnedValue to u8
|
// Attempt to convert OwnedValue to u8
|
||||||
@ -24,27 +22,18 @@ impl Notification {
|
|||||||
Ok(0) => "Low".to_string(),
|
Ok(0) => "Low".to_string(),
|
||||||
Ok(1) => "Normal".to_string(),
|
Ok(1) => "Normal".to_string(),
|
||||||
Ok(2) => "Critical".to_string(),
|
Ok(2) => "Critical".to_string(),
|
||||||
_ => "Other".to_string(), // There are no accepted values other that these 3
|
_ => "Unknown".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => "Unknown".to_string(), // This possibly never occurs, or something might be wrong
|
None => "Unknown".to_string(),
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn actions(&self) -> HashMap<String, String> {
|
|
||||||
let mut acts: HashMap<String, String>;
|
|
||||||
for i in Range(self.actions.len()) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_notif(msg_body: &Body) -> Result<Notification> {
|
pub fn to_notif(msg_body: &Body) -> Result<Notification> {
|
||||||
// Convert the DBus message body into Notification
|
|
||||||
let (app_name, replace_id, icon, summary, body, actions, hints, expir_timeout) =
|
let (app_name, replace_id, icon, summary, body, actions, hints, expir_timeout) =
|
||||||
msg_body.deserialize()?; // Deserialized into a tuple
|
msg_body.deserialize()?;
|
||||||
Ok(Notification {
|
Ok(Notification {
|
||||||
// Make a Notification object from the obtained tuple
|
|
||||||
app_name,
|
app_name,
|
||||||
replace_id,
|
replace_id,
|
||||||
icon,
|
icon,
|
||||||
|
Loading…
Reference in New Issue
Block a user