diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index 21b2fa2..a72319c 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -3,7 +3,6 @@ package pomodoro import ( "git.smsvc.net/pomodoro/GoTomato/internal/broadcast" "git.smsvc.net/pomodoro/GoTomato/pkg/models" - "github.com/gorilla/websocket" "sync" ) @@ -14,7 +13,7 @@ var pomodoroResumeChannel = make(chan bool, 1) var mu sync.Mutex // to synchronize access to shared state // RunPomodoro iterates the Pomodoro work/break sessions. -func RunPomodoro(clients map[*websocket.Conn]*models.Client, config models.GoTomatoPomodoroConfig) { +func RunPomodoro(config models.GoTomatoPomodoroConfig) { mu.Lock() broadcast.Message.Ongoing = true broadcast.Message.Paused = false @@ -24,15 +23,15 @@ func RunPomodoro(clients map[*websocket.Conn]*models.Client, config models.GoTom for session := 1; session <= config.Sessions; session++ { broadcast.Message.Session = session - if !startTimer(clients, config.Work, "Work") { + if !startTimer(config.Work, "Work") { break } if session == config.Sessions { - if !startTimer(clients, config.LongBreak, "LongBreak") { + if !startTimer(config.LongBreak, "LongBreak") { break } } else { - if !startTimer(clients, config.ShortBreak, "ShortBreak") { + if !startTimer(config.ShortBreak, "ShortBreak") { break } } @@ -44,7 +43,7 @@ func RunPomodoro(clients map[*websocket.Conn]*models.Client, config models.GoTom } // ResetPomodoro resets the running Pomodoro timer. -func ResetPomodoro(clients map[*websocket.Conn]*models.Client) { +func ResetPomodoro() { // Send a reset signal to stop any running timers pomodoroResetChannel <- true diff --git a/internal/pomodoro/timer.go b/internal/pomodoro/timer.go index 272b989..30466c6 100644 --- a/internal/pomodoro/timer.go +++ b/internal/pomodoro/timer.go @@ -2,13 +2,11 @@ package pomodoro import ( "git.smsvc.net/pomodoro/GoTomato/internal/broadcast" - "git.smsvc.net/pomodoro/GoTomato/pkg/models" - "github.com/gorilla/websocket" "time" ) // startTimer runs the countdown and broadcasts every second. -func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int, mode string) bool { +func startTimer(remainingSeconds int, mode string) bool { for remainingSeconds > 0 { select { case <-pomodoroResetChannel: diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index b1c6f88..8952fd0 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -43,11 +43,11 @@ func handleClientCommands(ws *websocket.Conn) { if clientCommand.Config != unsetPomodoroConfig { pomodoroConfig = clientCommand.Config } - go pomodoro.RunPomodoro(broadcast.Clients, pomodoroConfig) // Start the timer with the list of clients + go pomodoro.RunPomodoro(pomodoroConfig) // Start the timer with the list of clients } case "stop": if pomodoro.IsPomodoroOngoing() { - pomodoro.ResetPomodoro(broadcast.Clients) // Reset Pomodoro + pomodoro.ResetPomodoro() // Reset Pomodoro } case "pause": if pomodoro.IsPomodoroOngoing() && !pomodoro.IsPomodoroPaused() {