minor cleanup

This commit is contained in:
lelgenio 2022-02-07 20:05:28 -03:00
parent a4e4cdd851
commit 5cdd18fb72

View file

@ -1,3 +1,5 @@
use std::path::PathBuf;
use hotwatch::blocking::{ use hotwatch::blocking::{
Flow, Flow,
Hotwatch, Hotwatch,
@ -9,35 +11,28 @@ use mailparse::{
use notify_rust::Notification; use notify_rust::Notification;
fn main() { fn main() {
let args = std::env::args(); // .collect::<Vec<_>>();
// let path = args.get(1).expect("No path provided, exiting");
let mut hotwatch = let mut hotwatch =
Hotwatch::new_with_custom_delay(std::time::Duration::from_secs(0)) Hotwatch::new_with_custom_delay(std::time::Duration::from_secs(0))
.expect("hotwatch failed to initialize!"); .expect("hotwatch failed to initialize!");
println!("starting"); std::env::args().for_each(|arg| {
for arg in args {
hotwatch hotwatch
.watch(arg, handle_event) .watch(arg, handle_event)
.expect("hotwatch failed to initialize!"); .expect("hotwatch failed to initialize!");
} });
hotwatch.run(); hotwatch.run();
println!("exiting");
} }
fn handle_event(event: hotwatch::Event) -> hotwatch::blocking::Flow { fn handle_event(event: hotwatch::Event) -> hotwatch::blocking::Flow {
_handle_event(event); if let hotwatch::Event::Create(newfile) = event {
_handle_event(newfile)
};
Flow::Continue Flow::Continue
} }
fn _handle_event(event: hotwatch::Event) { fn _handle_event(newfile: PathBuf) {
let newfile = match dbg! {event} {
hotwatch::Event::Create(newfile) => newfile,
_ => return,
};
let raw_content = match std::fs::read_to_string(&newfile) { let raw_content = match std::fs::read_to_string(&newfile) {
Ok(c) => c, Ok(c) => c,
Err(e) => { Err(e) => {
@ -64,8 +59,6 @@ fn _handle_event(event: hotwatch::Event) {
let headers = mail_content.get_headers(); let headers = mail_content.get_headers();
eprintln!("getting from field");
let from = match headers.get_first_value("From") { let from = match headers.get_first_value("From") {
Some(f) => f, Some(f) => f,
None => { None => {
@ -74,8 +67,6 @@ fn _handle_event(event: hotwatch::Event) {
} }
}; };
eprintln!("getting subject field");
let subject = match headers.get_first_value("Subject") { let subject = match headers.get_first_value("Subject") {
Some(sub) => sub, Some(sub) => sub,
None => mail_content None => mail_content
@ -88,10 +79,6 @@ fn _handle_event(event: hotwatch::Event) {
.to_string(), .to_string(),
}; };
eprintln!("setting subject field to {}", &subject);
eprintln!("showing notification");
Notification::new() Notification::new()
.summary(&format!("From: {}", from)) .summary(&format!("From: {}", from))
.body(&format!("Subject: {}", subject)) .body(&format!("Subject: {}", subject))