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
|
@ -7,13 +7,6 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
var PomodoroConfig = models.GoTomatoPomodoroConfig{
|
||||
Work: 15 * 60,
|
||||
ShortBreak: 5 * 60,
|
||||
LongBreak: 10 * 60,
|
||||
Sessions: 4,
|
||||
}
|
||||
|
||||
var pomodoroOngoing bool
|
||||
var pomodoroPaused bool
|
||||
|
||||
|
@ -24,22 +17,22 @@ var pomodoroResumeChannel = make(chan bool, 1)
|
|||
var mu sync.Mutex // to synchronize access to shared state
|
||||
|
||||
// RunPomodoro iterates the Pomodoro work/break sessions.
|
||||
func RunPomodoro(clients map[*websocket.Conn]*models.Client) {
|
||||
func RunPomodoro(clients map[*websocket.Conn]*models.Client, config models.GoTomatoPomodoroConfig) {
|
||||
mu.Lock()
|
||||
pomodoroOngoing = true
|
||||
pomodoroPaused = false
|
||||
mu.Unlock()
|
||||
|
||||
for session := 1; session <= PomodoroConfig.Sessions; session++ {
|
||||
if !startTimer(clients, PomodoroConfig.Work, "Work", session) {
|
||||
for session := 1; session <= config.Sessions; session++ {
|
||||
if !startTimer(clients, config.Work, "Work", session, config.Sessions) {
|
||||
break
|
||||
}
|
||||
if session == PomodoroConfig.Sessions {
|
||||
if !startTimer(clients, PomodoroConfig.LongBreak, "LongBreak", session) {
|
||||
if session == config.Sessions {
|
||||
if !startTimer(clients, config.LongBreak, "LongBreak", session, config.Sessions) {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if !startTimer(clients, PomodoroConfig.ShortBreak, "ShortBreak", session) {
|
||||
if !startTimer(clients, config.ShortBreak, "ShortBreak", session, config.Sessions) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue