feat(pomodoro): update timer management
- rename timerRunning to pomodoroRunning
- move function and timer definition to correct source file
🤖
This commit is contained in:
parent
90f80cc685
commit
2a4ebf07ba
3 changed files with 10 additions and 10 deletions
|
@ -12,12 +12,13 @@ const (
|
|||
sessions = 4
|
||||
)
|
||||
|
||||
var pomodoroRunning bool
|
||||
var mu sync.Mutex // to synchronize access to shared state
|
||||
|
||||
// RunPomodoroTimer iterates the Pomodoro work/break sessions.
|
||||
func RunPomodoroTimer(clients map[*websocket.Conn]bool) {
|
||||
mu.Lock()
|
||||
timerRunning = true
|
||||
pomodoroRunning = true
|
||||
|
||||
for session := 1; session <= sessions; session++ {
|
||||
if !startTimer(clients, workDuration, "Work", session) {
|
||||
|
@ -34,6 +35,11 @@ func RunPomodoroTimer(clients map[*websocket.Conn]bool) {
|
|||
}
|
||||
}
|
||||
|
||||
timerRunning = false
|
||||
pomodoroRunning = false
|
||||
mu.Unlock()
|
||||
}
|
||||
|
||||
// IsPomodoroRunning returns the status of the timer.
|
||||
func IsPomodoroRunning() bool {
|
||||
return pomodoroRunning
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var timerRunning bool
|
||||
var timerStopChannel = make(chan bool, 1)
|
||||
|
||||
// startTimer runs the countdown and broadcasts every second.
|
||||
|
@ -44,8 +43,3 @@ func startTimer(clients map[*websocket.Conn]bool, remainingSeconds int, mode str
|
|||
func StopTimer() {
|
||||
timerStopChannel <- true
|
||||
}
|
||||
|
||||
// IsTimerRunning returns the status of the timer.
|
||||
func IsTimerRunning() bool {
|
||||
return timerRunning
|
||||
}
|
||||
|
|
|
@ -29,11 +29,11 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
// Process the command
|
||||
switch command.Command {
|
||||
case "start":
|
||||
if !pomodoro.IsTimerRunning() {
|
||||
if !pomodoro.PomodoroRunning() {
|
||||
go pomodoro.RunPomodoroTimer(Clients) // Start the timer with the list of clients
|
||||
}
|
||||
case "stop":
|
||||
if pomodoro.IsTimerRunning() {
|
||||
if pomodoro.PomodoroRunning() {
|
||||
pomodoro.StopTimer() // Stop the timer in the Pomodoro package
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue