diff --git a/index.html b/index.html index 5bde13c..248ca61 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,7 @@ - + diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index 3010244..6297d45 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -1,6 +1,8 @@ package pomodoro import ( + "git.smsvc.net/pomodoro/GoTomato/internal/broadcast" + "git.smsvc.net/pomodoro/GoTomato/pkg/models" "github.com/gorilla/websocket" "sync" ) @@ -15,7 +17,7 @@ const ( var pomodoroRunning bool var pomodoroPaused bool -var pomodoroStopChannel = make(chan bool, 1) +var pomodoroResetChannel = make(chan bool, 1) var pomodoroPauseChannel = make(chan bool, 1) var pomodoroResumeChannel = make(chan bool, 1) @@ -48,9 +50,23 @@ func RunPomodoroTimer(clients map[*websocket.Conn]bool) { mu.Unlock() } -// StopPomodoro sends a signal to stop the running Pomodoro timer. -func StopPomodoro() { - pomodoroStopChannel <- true +// ResetPomodoro resets the running Pomodoro timer. +func ResetPomodoro(clients map[*websocket.Conn]bool) { + mu.Lock() + pomodoroRunning = false // Reset the running state + pomodoroPaused = false // Reset the paused state + mu.Unlock() + + // Broadcast the reset message to all clients + broadcast.BroadcastMessage(clients, models.BroadcastMessage{ + Mode: "none", + Session: 0, + MaxSession: 0, + TimeLeft: 0, + }) + + // Send a reset signal to stop any running timers + pomodoroResetChannel <- true } func PausePomodoro() { diff --git a/internal/pomodoro/timer.go b/internal/pomodoro/timer.go index 28a7f09..6a8e39b 100644 --- a/internal/pomodoro/timer.go +++ b/internal/pomodoro/timer.go @@ -11,8 +11,8 @@ import ( func startTimer(clients map[*websocket.Conn]bool, remainingSeconds int, mode string, session int) bool { for remainingSeconds > 0 { select { - case <-pomodoroStopChannel: - return false // Stop the timer if a stop command is received + case <-pomodoroResetChannel: + return false case <-pomodoroPauseChannel: mu.Lock() pomodoroPaused = true diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index 74f2b4a..50fab15 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -34,7 +34,7 @@ func handleClientCommands(ws *websocket.Conn) { } case "stop": if pomodoro.IsPomodoroRunning() { - pomodoro.StopPomodoro() // Stop the timer in the Pomodoro package + pomodoro.ResetPomodoro(Clients) // Reset Pomodoro } case "pause": if pomodoro.IsPomodoroRunning() && !pomodoro.IsPomodoroPaused() {