diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index c8a3b03..5599af7 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -7,12 +7,12 @@ import ( "sync" ) -const ( - workDuration = 15 * 60 - shortBreakDuration = 5 * 60 - longBreakDuration = 10 * 60 - sessions = 4 -) +var PomodoroConfig = models.GoTomatoTimerConfig{ + Work: 15 * 60, + ShortBreak: 5 * 60, + LongBreak: 10 * 60, + Sessions: 4, +} var pomodoroRunning bool var pomodoroPaused bool @@ -30,16 +30,16 @@ func RunPomodoroTimer(clients map[*websocket.Conn]*models.Client) { pomodoroPaused = false mu.Unlock() - for session := 1; session <= sessions; session++ { - if !startTimer(clients, workDuration, "Work", session) { + for session := 1; session <= PomodoroConfig.Sessions; session++ { + if !startTimer(clients, PomodoroConfig.Work, "Work", session) { break } - if session == sessions { - if !startTimer(clients, longBreakDuration, "LongBreak", session) { + if session == PomodoroConfig.Sessions { + if !startTimer(clients, PomodoroConfig.LongBreak, "LongBreak", session) { break } } else { - if !startTimer(clients, shortBreakDuration, "ShortBreak", session) { + if !startTimer(clients, PomodoroConfig.ShortBreak, "ShortBreak", session) { break } } diff --git a/internal/pomodoro/timer.go b/internal/pomodoro/timer.go index 96595b3..e4d95dd 100644 --- a/internal/pomodoro/timer.go +++ b/internal/pomodoro/timer.go @@ -23,7 +23,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int broadcast.BroadcastMessage(clients, models.BroadcastMessage{ Mode: mode, Session: session, - MaxSession: sessions, + MaxSession: PomodoroConfig.Sessions, TimeLeft: remainingSeconds, }) time.Sleep(time.Second) @@ -36,7 +36,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int broadcast.BroadcastMessage(clients, models.BroadcastMessage{ Mode: mode, Session: session, - MaxSession: sessions, + MaxSession: PomodoroConfig.Sessions, TimeLeft: 0, }) diff --git a/pkg/models/config.go b/pkg/models/config.go index 59db277..628e685 100644 --- a/pkg/models/config.go +++ b/pkg/models/config.go @@ -1,5 +1,12 @@ package models +type GoTomatoTimerConfig struct { + Work int `json:"work"` + ShortBreak int `json:"shortBreak"` + LongBreak int `json:"longBreak"` + Sessions int `json:"sessions"` +} + type GoTomatoServerConfig struct { ListenAddress string `json:"listenAddress"` ListenPort int `json:"listenPort"`