break: change the "stop" command to "reset"
- change stop channel to reset channel
- create ResetPomodoro function
- broadcast reset message to all clients
- rename stop button to reset button in index.html
🤖
This commit is contained in:
parent
bc3a306c00
commit
ffc6913344
4 changed files with 28 additions and 12 deletions
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue