Browse Source

Add check for dependecies

master
Schneider 3 years ago
parent
commit
9fa4d841e6
  1. 19
      src/main.rs

19
src/main.rs

@ -1,5 +1,6 @@
use chrono::prelude::*; use chrono::prelude::*;
use chrono::Duration; use chrono::Duration;
use std::io::Error;
use std::io::{stdout, Result, StdoutLock, Write}; use std::io::{stdout, Result, StdoutLock, Write};
use std::process::{Command, Output}; use std::process::{Command, Output};
use std::thread::sleep; use std::thread::sleep;
@ -10,10 +11,28 @@ fn main() {
run().unwrap(); 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").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 /// Runs the application
/// ///
/// Default time settings are 25 minutes for a working block and 5 minutes for a break. /// Default time settings are 25 minutes for a working block and 5 minutes for a break.
fn run() -> Result<()> { 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 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 }); let break_duration = Duration::seconds(if cfg!(debug_assertions) { 5 } else { 5 * 60 });

Loading…
Cancel
Save