2 Commits

  1. 26
      src/main.rs

26
src/main.rs

@ -1,6 +1,8 @@
use chrono::prelude::*;
use chrono::Duration;
use std::io::Error;
use std::io::{stdout, Result, StdoutLock, Write};
use std::process::Stdio;
use std::process::{Command, Output};
use std::thread::sleep;
@ -10,10 +12,34 @@ fn main() {
run().unwrap();
}
/// Check if kdialog exists. If not, print message and return Err()
fn check_deps() -> Result<()> {
let cmd = Command::new("sh")
.arg("-c")
.arg("kdialog")
.arg("--version")
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()?;
if !cmd.success() {
println!("Could not find command 'kdialog'. Please install first, then start again");
return Err(Error::new(
std::io::ErrorKind::Other,
"Could not find kdialog",
));
}
return Ok(());
}
/// Runs the application
///
/// Default time settings are 25 minutes for a working block and 5 minutes for a break.
fn run() -> Result<()> {
if check_deps().is_err() {
// terminate gracefully
return Ok(());
}
let work_duration = Duration::seconds(if cfg!(debug_assertions) { 75 } else { 25 * 60 });
let break_duration = Duration::seconds(if cfg!(debug_assertions) { 5 } else { 5 * 60 });

Loading…
Cancel
Save