-
Notifications
You must be signed in to change notification settings - Fork 4
Description
break-time has two features that don't play nice with each other:
-
break-time will not start a break if you have an X window open with a given window title. This is to stop a break occurring when you are in a video chat. break-time will also check your Google Calendar to make sure you are not in a meeting. If you have a meeting scheduled in your calendar, break-time will not start a break.
The plugin-related code can be found here: https://github.com/cdepillabout/break-time/tree/6bad134cf96089ebd0ee372412d83d896b9f8633/src/scheduler/plugins
-
break-time will create a countdown timer in the systray icon when a break gets close. This appears as a red
5m,4m,3m, etc.The systray icon code can found here: https://github.com/cdepillabout/break-time/blob/6bad134cf96089ebd0ee372412d83d896b9f8633/src/tray.rs
Currently, the countdown timer will appear in the systray even if you are currently in a video chat, or there is currently a meeting on your Google Calendar.
This isn't a bug, per se, but it would be better if the countdown timer didn't appear until you finished your video chat or Google Calendar event.
Here is the code that controls the count down to the break, as well as calling the plugins at the appropriate time:
Lines 141 to 254 in 6bad134
| fn run_loop(&mut self) -> ! { | |
| loop { | |
| match self.state { | |
| State::CountDownToBreak => { | |
| let wait_until_break_result = self.wait_until_break(); | |
| match wait_until_break_result { | |
| WaitUntilBreakResult::FinishedWaiting => { | |
| self.state = State::WaitingForBreakEnd; | |
| } | |
| WaitUntilBreakResult::Paused => { | |
| self.state = State::Paused; | |
| } | |
| } | |
| } | |
| State::Paused | State::WaitingForBreakEnd => { | |
| // Wait for a message signalling a break ending or a pause ending. | |
| println!("Scheduler currently waiting for a message signaling either a break or a pause ending."); | |
| let msg = self | |
| .break_ending_receiver | |
| .recv() | |
| .expect("Error receiving value in Scheduler."); | |
| match msg { | |
| Msg::Start => { | |
| self.state = State::CountDownToBreak; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| fn wait_until_break(&self) -> WaitUntilBreakResult { | |
| loop { | |
| let waiting_result = self.send_msgs_while_waiting(); | |
| match waiting_result { | |
| WaitingResult::Finished => { | |
| println!( | |
| "Scheduler successfully finished sleeping, checking if it can break now..." | |
| ); | |
| let (opt_can_break, errs) = self.plugins.can_break_now(); | |
| if errs.is_empty() { | |
| match opt_can_break { | |
| None => panic!("If there are no errors, then we should always get a response to can_break"), | |
| Some(can_break) => { | |
| if can_break.into_bool() { | |
| println!("Scheduler realized it was able to break, so sending a message."); | |
| self.sender.send(super::Msg::StartBreak); | |
| return WaitUntilBreakResult::FinishedWaiting; | |
| } else { | |
| println!("Could not break right now, so sleeping again..."); | |
| } | |
| } | |
| } | |
| } else { | |
| println!( | |
| "There have been some errors from our plugins:" | |
| ); | |
| for e in errs { | |
| println!("{}", e); | |
| } | |
| println!("Sleeping again just to be safe..."); | |
| } | |
| } | |
| WaitingResult::NeedToRestart => { | |
| // Just let this loop restart. | |
| println!( | |
| "Scheduler got a message to restart sleeping again, probably because X has been idle..." | |
| ); | |
| } | |
| WaitingResult::Paused => { | |
| return WaitUntilBreakResult::Paused; | |
| } | |
| } | |
| } | |
| } | |
| fn send_msgs_while_waiting(&self) -> WaitingResult { | |
| self.sender.send(super::Msg::ResetSysTrayIcon); | |
| let mut remaining_time = self.time_until_break; | |
| for period in create_periods_to_send_time_left_message(self.time_until_break) { | |
| let opt_time_to_sleep = remaining_time.checked_sub(period); | |
| println!("In send_msgs_while_waiting loop for period {:?}, remaining_time: {:?}, time_to_sleep: {:?}", period, remaining_time, opt_time_to_sleep); | |
| match opt_time_to_sleep { | |
| None => { | |
| // This happens when the periods to send the time-left message are greater than | |
| // the remaining time. We can just skip this. | |
| } | |
| Some(time_to_sleep) => { | |
| let res = self | |
| .restart_wait_time_receiver | |
| .recv_timeout(time_to_sleep); | |
| match res { | |
| Ok(InnerMsg::HasBeenIdle) => { | |
| println!("HERERERERE"); | |
| return WaitingResult::NeedToRestart; | |
| } | |
| Ok(InnerMsg::Pause) => { | |
| println!("Got inner message to pause..."); | |
| return WaitingResult::Paused; | |
| } | |
| Err(_) => { | |
| self.sender.send( | |
| super::Msg::TimeRemainingBeforeBreak(period), | |
| ); | |
| remaining_time -= time_to_sleep; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| return WaitingResult::Finished; | |
| } |
One way to solve this is to call the plugins before showing the countdown timer (which happens when only 5 minutes are left), and if the plugins indicate that you are currently in a meeting, or have a given window open, then pushing back the next break by 10 or 15 minutes or so.