feat: simplify timer function

- remove "mode" parameter from startTimer function
- update shared.Message.Mode for each pomodoro state
- update comments

🤖
This commit is contained in:
Sebastian Mark 2024-10-21 09:34:36 +02:00
parent 6ffd9f1e38
commit 03ab627729
2 changed files with 9 additions and 7 deletions

View file

@ -23,15 +23,18 @@ func RunPomodoro(config models.GoTomatoPomodoroConfig) {
for session := 1; session <= config.Sessions; session++ {
shared.Message.Session = session
if !startTimer(config.Work, "Work") {
shared.Message.Mode = "Work"
if !startTimer(config.Work) {
break
}
if session == config.Sessions {
if !startTimer(config.LongBreak, "LongBreak") {
shared.Message.Mode = "LongBreak"
if !startTimer(config.LongBreak) {
break
}
} else {
if !startTimer(config.ShortBreak, "ShortBreak") {
shared.Message.Mode = "ShortBreak"
if !startTimer(config.ShortBreak) {
break
}
}

View file

@ -5,8 +5,8 @@ import (
"time"
)
// startTimer runs the countdown and shared. every second.
func startTimer(remainingSeconds int, mode string) bool {
// runs the countdown and updates shared.Message.TimeLeft every second.
func startTimer(remainingSeconds int) bool {
for remainingSeconds > 0 {
select {
case <-pomodoroResetChannel:
@ -18,7 +18,6 @@ func startTimer(remainingSeconds int, mode string) bool {
default:
// Broadcast the current state to all clients
if !IsPomodoroPaused() {
shared.Message.Mode = mode
shared.Message.TimeLeft = remainingSeconds
time.Sleep(time.Second)
remainingSeconds--
@ -26,7 +25,7 @@ func startTimer(remainingSeconds int, mode string) bool {
}
}
// Final shared.when time reaches zero
// Final shared.Message when time reaches zero
shared.Message.TimeLeft = remainingSeconds
return true