diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index 02325ac..65705fe 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -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 +} diff --git a/internal/pomodoro/timer.go b/internal/pomodoro/timer.go index 13364a1..c7d931b 100644 --- a/internal/pomodoro/timer.go +++ b/internal/pomodoro/timer.go @@ -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 -} diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index fe79513..41855bf 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -29,11 +29,11 @@ func handleClientCommands(ws *websocket.Conn) { // Process the command switch command.Command { case "start": - if !pomodoro.IsTimerRunning() { + if !pomodoro.IsPomodoroRunning() { go pomodoro.RunPomodoroTimer(Clients) // Start the timer with the list of clients } case "stop": - if pomodoro.IsTimerRunning() { + if pomodoro.IsPomodoroRunning() { pomodoro.StopTimer() // Stop the timer in the Pomodoro package } }