dev #2

Merged
candifloss merged 10 commits from dev into main 2024-09-27 10:06:26 +00:00
Showing only changes of commit a6b95bad57 - Show all commits

View File

@ -7,7 +7,6 @@ pub mod formats {
mod notification; mod notification;
use notification::{to_notif, Notification}; use notification::{to_notif, Notification};
use std::collections::HashMap; use std::collections::HashMap;
// use std::env;
pub mod optparse; pub mod optparse;
use futures_util::stream::TryStreamExt; use futures_util::stream::TryStreamExt;
@ -33,19 +32,27 @@ fn server_properties() -> HashMap<String, String> {
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
// Options
let args: optparse::Cli = argh::from_env(); let args: optparse::Cli = argh::from_env();
// Format: r|j|p
let op_format = match args.format { let op_format = match args.format {
Some(value) => value.clone(), Some(value) => {
// Reject invalid format option
if ["r", "j", "p"].contains(&value.as_str()) {
value.clone()
} else {
// Exit with error code
return Err(zbus::Error::from(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid output format",
)));
}
}
None => "j".to_string(), None => "j".to_string(),
}; };
if !["r", "j", "p"].contains(&op_format.as_str()) { // Verbose mode. Off/false by default
return Err(zbus::Error::from(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid output format",
)));
}
let verbose = args.verbose; let verbose = args.verbose;
let connection = Connection::session().await?; let connection = Connection::session().await?;
@ -131,12 +138,12 @@ async fn main() -> Result<()> {
println!("{}\n", &notif.plain()); // Print the plain version println!("{}\n", &notif.plain()); // Print the plain version
} }
_ => { _ => {
println!("Onkown output format."); println!("Onkown output format."); // This is probably unreachable
} }
} }
} }
"CloseNotification" => { "CloseNotification" => {
// Client sent a close signal. Extract notification ID of the notif to be closed from the message body // Client sent a 'close' signal. Extract notification ID of the notif to be closed from the message body
let notification_id: u32 = msg.body().deserialize()?; // This method has only one parameter, the id let notification_id: u32 = msg.body().deserialize()?; // This method has only one parameter, the id
// Tracking notifications by their IDs, closing them, and other features may be implemented later // Tracking notifications by their IDs, closing them, and other features may be implemented later