From 9fa4d841e6754ef6afc8687df9bd2138958269ed Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Wed, 24 Nov 2021 11:16:51 +0100 Subject: [PATCH] Add check for dependecies --- src/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.rs b/src/main.rs index 4849481..844f6f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use chrono::prelude::*; use chrono::Duration; +use std::io::Error; use std::io::{stdout, Result, StdoutLock, Write}; use std::process::{Command, Output}; use std::thread::sleep; @@ -10,10 +11,28 @@ 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").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 });