feat: allow clients to send pomodoro config
- allow clients to send custom configuration for pomodoro sessions
- update RunPomodoro to accept a configuration parameter
- modify startTimer to handle session count from config
- add default pomodoro configuration in client command handling
🤖
This commit is contained in:
parent
9149b1a78e
commit
2ac1aecba1
6 changed files with 46 additions and 22 deletions
|
@ -8,9 +8,19 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
var unsetPomodoroConfig models.GoTomatoPomodoroConfig // used to check if client passed a config json
|
||||
|
||||
// handleClientCommands listens for commands from WebSocket clients and dispatches to the timer.
|
||||
func handleClientCommands(ws *websocket.Conn) {
|
||||
for {
|
||||
var clientCommand models.ClientCommand
|
||||
var pomodoroConfig = models.GoTomatoPomodoroConfig{
|
||||
Work: 25 * 60,
|
||||
ShortBreak: 5 * 60,
|
||||
LongBreak: 15 * 60,
|
||||
Sessions: 4,
|
||||
}
|
||||
|
||||
_, message, err := ws.ReadMessage()
|
||||
if err != nil {
|
||||
log.Printf("Client disconnected: %v", err)
|
||||
|
@ -19,18 +29,20 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
}
|
||||
|
||||
// Handle incoming commands
|
||||
var command models.ClientCommand
|
||||
err = json.Unmarshal(message, &command)
|
||||
err = json.Unmarshal(message, &clientCommand)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshalling command: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Process the command
|
||||
switch command.Command {
|
||||
switch clientCommand.Command {
|
||||
case "start":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
go pomodoro.RunPomodoro(Clients) // Start the timer with the list of clients
|
||||
if clientCommand.Config != unsetPomodoroConfig {
|
||||
pomodoroConfig = clientCommand.Config
|
||||
}
|
||||
go pomodoro.RunPomodoro(Clients, pomodoroConfig) // Start the timer with the list of clients
|
||||
}
|
||||
case "stop":
|
||||
if pomodoro.IsPomodoroOngoing() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue