TatriX / pomidor

Pomidor is a simple and cool pomodoro technique timer.
239 stars 17 forks source link

Fixing function that notifies when break ends #11

Closed vfinotti closed 6 years ago

vfinotti commented 6 years ago

When the algorithm hasn't started the break, the current status is something like (:started (23119 32850 428356 983000) :break nil :stopped nil). The function that returns the break duration is shown bellow:

(defun pomidor--break-duration (state)
  "Return break time for STATE."
  (let ((break (pomidor--break state)))
    (and break (time-subtract (pomidor--ended state) break))))

When :break is nil, the function always returns a big number, since the operation (time-subtract (pomidor--ended state) break)) it is evaluated to (time-subtract current-time nil)). A possible solution is to force the notify function to verify if :break is nil:

 ;; notify me after my 5 minutes break 
(defun my-pomidor-update-hook ()
  (let ((break-duration (* 60 5)) ;; seconds
        (ellapsed (time-to-seconds (pomidor-break-duration))))
    (when (and (> ellapsed break-duration) (pomidor--break (pomidor--current-state)))
      (pomidor-play-sound-file-async pomidor-sound-overwork))))

However, a more permanent solution would be changing pomidor-break-duration to return 0 or nil when :break is nil.

TatriX commented 6 years ago

Cool, thanks!