diff options
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/pomo.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/daemon/pomo.rs b/src/daemon/pomo.rs index 3129e7d..1f4d8ef 100644 --- a/src/daemon/pomo.rs +++ b/src/daemon/pomo.rs @@ -16,6 +16,7 @@ */ use bincode::{Encode, Decode}; +use std::env; #[derive(Encode, Decode, PartialEq, Clone, Copy)] pub enum State { @@ -32,14 +33,14 @@ pub enum State { #[derive(Encode, Decode)] pub struct Pomo { - work_duration: u64, - break_duration: u64, - long_break_duration: u64, - long_break_interval: u64, + work_duration: u16, + break_duration: u16, + long_break_duration: u16, + long_break_interval: u16, // only these are supposed to change - pub secs_elapsed: u64, - pub counter: u64, + pub secs_elapsed: u16, + pub counter: u16, pub current_state: State, } @@ -50,11 +51,10 @@ impl Pomo { counter: 1, current_state: State::WorkIdle, - // TODO: load from config, probably - work_duration: 25,// * 60, - break_duration: 5,// * 60, - long_break_duration: 20,// * 60, - long_break_interval: 4, + work_duration: get_envvar("WORK_DURATION", 25 * 60), + break_duration: get_envvar("BREAK_DURATION", 5 * 60), + long_break_duration: get_envvar("LONG_BREAK_DURATION", 20 * 60), + long_break_interval: get_envvar("LONG_BREAK_INTERVAL", 4), } } @@ -158,3 +158,11 @@ impl Pomo { } } } + + +fn get_envvar(key: &str, def: u16) -> u16 { + env::var(key) + .ok() + .and_then(|v| v.parse::<u16>().ok()) + .unwrap_or(def) +} |