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:
parent
6ffd9f1e38
commit
03ab627729
2 changed files with 9 additions and 7 deletions
|
@ -23,15 +23,18 @@ func RunPomodoro(config models.GoTomatoPomodoroConfig) {
|
||||||
|
|
||||||
for session := 1; session <= config.Sessions; session++ {
|
for session := 1; session <= config.Sessions; session++ {
|
||||||
shared.Message.Session = session
|
shared.Message.Session = session
|
||||||
if !startTimer(config.Work, "Work") {
|
shared.Message.Mode = "Work"
|
||||||
|
if !startTimer(config.Work) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if session == config.Sessions {
|
if session == config.Sessions {
|
||||||
if !startTimer(config.LongBreak, "LongBreak") {
|
shared.Message.Mode = "LongBreak"
|
||||||
|
if !startTimer(config.LongBreak) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !startTimer(config.ShortBreak, "ShortBreak") {
|
shared.Message.Mode = "ShortBreak"
|
||||||
|
if !startTimer(config.ShortBreak) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// startTimer runs the countdown and shared. every second.
|
// runs the countdown and updates shared.Message.TimeLeft every second.
|
||||||
func startTimer(remainingSeconds int, mode string) bool {
|
func startTimer(remainingSeconds int) bool {
|
||||||
for remainingSeconds > 0 {
|
for remainingSeconds > 0 {
|
||||||
select {
|
select {
|
||||||
case <-pomodoroResetChannel:
|
case <-pomodoroResetChannel:
|
||||||
|
@ -18,7 +18,6 @@ func startTimer(remainingSeconds int, mode string) bool {
|
||||||
default:
|
default:
|
||||||
// Broadcast the current state to all clients
|
// Broadcast the current state to all clients
|
||||||
if !IsPomodoroPaused() {
|
if !IsPomodoroPaused() {
|
||||||
shared.Message.Mode = mode
|
|
||||||
shared.Message.TimeLeft = remainingSeconds
|
shared.Message.TimeLeft = remainingSeconds
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
remainingSeconds--
|
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
|
shared.Message.TimeLeft = remainingSeconds
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue