feat: create shared config defaults
- add shared configuration defaults for server and pomodoro
🤖
This commit is contained in:
parent
28342058aa
commit
a9d145ee71
3 changed files with 26 additions and 11 deletions
|
@ -3,23 +3,17 @@ package websocket
|
|||
import (
|
||||
"encoding/json"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/pomodoro"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"github.com/gorilla/websocket"
|
||||
"log"
|
||||
)
|
||||
|
||||
var unsetPomodoroConfig models.GoTomatoPomodoroConfig // used to check if client passed a config json
|
||||
|
||||
// handleClientCommands listens for commands from WebSocket clients
|
||||
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,
|
||||
}
|
||||
var pomodoroConfig = shared.DefaultPomodoroConfig
|
||||
|
||||
_, message, err := ws.ReadMessage()
|
||||
if err != nil {
|
||||
|
@ -39,7 +33,7 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
switch clientCommand.Command {
|
||||
case "start":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
if clientCommand.Config != unsetPomodoroConfig {
|
||||
if clientCommand.Config != shared.UnsetPomodoroConfig {
|
||||
pomodoroConfig = clientCommand.Config
|
||||
}
|
||||
go pomodoro.RunPomodoro(pomodoroConfig) // Start the timer with the list of clients
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue