feat: simplify pomodoro functions by removing client parameter
- remove clients parameter from RunPomodoro function
- update startTimer to no longer require clients parameter
- modify ResetPomodoro to eliminate clients parameter
- adjust client_commands to reflect changes in function signatures
🤖
This commit is contained in:
parent
9615d4d449
commit
234f3c17dc
3 changed files with 8 additions and 11 deletions
|
@ -3,7 +3,6 @@ package pomodoro
|
||||||
import (
|
import (
|
||||||
"git.smsvc.net/pomodoro/GoTomato/internal/broadcast"
|
"git.smsvc.net/pomodoro/GoTomato/internal/broadcast"
|
||||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ var pomodoroResumeChannel = make(chan bool, 1)
|
||||||
var mu sync.Mutex // to synchronize access to shared state
|
var mu sync.Mutex // to synchronize access to shared state
|
||||||
|
|
||||||
// RunPomodoro iterates the Pomodoro work/break sessions.
|
// 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()
|
mu.Lock()
|
||||||
broadcast.Message.Ongoing = true
|
broadcast.Message.Ongoing = true
|
||||||
broadcast.Message.Paused = false
|
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++ {
|
for session := 1; session <= config.Sessions; session++ {
|
||||||
broadcast.Message.Session = session
|
broadcast.Message.Session = session
|
||||||
if !startTimer(clients, config.Work, "Work") {
|
if !startTimer(config.Work, "Work") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if session == config.Sessions {
|
if session == config.Sessions {
|
||||||
if !startTimer(clients, config.LongBreak, "LongBreak") {
|
if !startTimer(config.LongBreak, "LongBreak") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !startTimer(clients, config.ShortBreak, "ShortBreak") {
|
if !startTimer(config.ShortBreak, "ShortBreak") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +43,7 @@ func RunPomodoro(clients map[*websocket.Conn]*models.Client, config models.GoTom
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetPomodoro resets the running Pomodoro timer.
|
// 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
|
// Send a reset signal to stop any running timers
|
||||||
pomodoroResetChannel <- true
|
pomodoroResetChannel <- true
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,11 @@ package pomodoro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smsvc.net/pomodoro/GoTomato/internal/broadcast"
|
"git.smsvc.net/pomodoro/GoTomato/internal/broadcast"
|
||||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// startTimer runs the countdown and broadcasts every second.
|
// 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 {
|
for remainingSeconds > 0 {
|
||||||
select {
|
select {
|
||||||
case <-pomodoroResetChannel:
|
case <-pomodoroResetChannel:
|
||||||
|
|
|
@ -43,11 +43,11 @@ func handleClientCommands(ws *websocket.Conn) {
|
||||||
if clientCommand.Config != unsetPomodoroConfig {
|
if clientCommand.Config != unsetPomodoroConfig {
|
||||||
pomodoroConfig = clientCommand.Config
|
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":
|
case "stop":
|
||||||
if pomodoro.IsPomodoroOngoing() {
|
if pomodoro.IsPomodoroOngoing() {
|
||||||
pomodoro.ResetPomodoro(broadcast.Clients) // Reset Pomodoro
|
pomodoro.ResetPomodoro() // Reset Pomodoro
|
||||||
}
|
}
|
||||||
case "pause":
|
case "pause":
|
||||||
if pomodoro.IsPomodoroOngoing() && !pomodoro.IsPomodoroPaused() {
|
if pomodoro.IsPomodoroOngoing() && !pomodoro.IsPomodoroPaused() {
|
||||||
|
|
Loading…
Reference in a new issue