refactor: factor out notification sending
parent
82d94650a5
commit
b53689584a
|
@ -1,7 +1,7 @@
|
|||
use crate::notification::send_notifictation;
|
||||
use crate::pomodoro::Pomodoro;
|
||||
pub use crate::timer::Timer;
|
||||
use anyhow::Context;
|
||||
use notify_rust::Notification;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::{
|
||||
|
@ -100,21 +100,14 @@ impl Daemon {
|
|||
}
|
||||
|
||||
if self.notify {
|
||||
match Notification::new()
|
||||
.summary(" Timers")
|
||||
.body(
|
||||
format!(
|
||||
"Started timer {} for {}",
|
||||
&name,
|
||||
humantime::format_duration(duration)
|
||||
)
|
||||
.as_str(),
|
||||
send_notifictation(
|
||||
format!(
|
||||
"Started timer {} for {}",
|
||||
&name,
|
||||
humantime::format_duration(duration)
|
||||
)
|
||||
.show()
|
||||
{
|
||||
Ok(_) => println!("Sent notification sucessfully."),
|
||||
Err(_) => println!("Failed to send notification."),
|
||||
};
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
let timer = Timer::new(name, duration);
|
||||
|
@ -135,14 +128,7 @@ impl Daemon {
|
|||
long_pause,
|
||||
pauses_till_long,
|
||||
} => {
|
||||
match Notification::new()
|
||||
.summary(" Timers")
|
||||
.body("Started pomodoro.")
|
||||
.show()
|
||||
{
|
||||
Ok(_) => println!("Sent notification sucessfully."),
|
||||
Err(_) => println!("Failed to send notification."),
|
||||
};
|
||||
send_notifictation("Started pomodoro.");
|
||||
self.pomodoro = Some(Pomodoro::new(work, pause, long_pause, pauses_till_long));
|
||||
Ok(Answer::Ok)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
pub mod cli;
|
||||
pub mod daemon;
|
||||
pub mod pomodoro;
|
||||
pub mod timer;
|
||||
mod cli;
|
||||
mod daemon;
|
||||
mod pomodoro;
|
||||
mod timer;
|
||||
mod notification;
|
||||
|
||||
use crate::cli::{send_command, Cli, Command as CliCommand};
|
||||
use crate::daemon::{Command as DaemonCommand, Daemon};
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
use notify_rust::Notification;
|
||||
|
||||
pub fn send_notifictation(msg: &str) {
|
||||
match Notification::new().summary(" Timers").body(msg).show() {
|
||||
Ok(_) => println!("Sent notification sucessfully."),
|
||||
Err(_) => println!("Failed to send notification."),
|
||||
};
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use notify_rust::Notification;
|
||||
use crate::notification::send_notifictation;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fmt::{Display, Formatter},
|
||||
|
@ -74,10 +74,7 @@ impl Timer {
|
|||
let msg = format!("Timer {} has expired!", self.name);
|
||||
println!("{}", &msg);
|
||||
if notify {
|
||||
match Notification::new().summary(" Timers").body(&msg).show() {
|
||||
Ok(_) => println!("Sent notification sucessfully."),
|
||||
Err(_) => println!("Failed to send notification."),
|
||||
}
|
||||
send_notifictation(msg.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue