break: add updateSettings
command to modify Pomodoro settings
- add `updateSettings` command to modify Pomodoro configuration
- remove ability to set Pomodoro configuration in `start` command
- update demo client
- update README
🤖
This commit is contained in:
parent
a0dba673a2
commit
cb6616f400
5 changed files with 75 additions and 59 deletions
internal
|
@ -2,7 +2,7 @@ package pomodoro
|
|||
|
||||
import (
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
// "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
@ -13,28 +13,28 @@ 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(config models.GoTomatoPomodoroConfig) {
|
||||
func RunPomodoro() {
|
||||
mu.Lock()
|
||||
shared.Message.Ongoing = true
|
||||
shared.Message.Paused = false
|
||||
mu.Unlock()
|
||||
|
||||
shared.Message.PomodoroSettings = config
|
||||
pomodoroConfig := shared.Message.PomodoroSettings
|
||||
|
||||
for session := 1; session <= config.Sessions; session++ {
|
||||
for session := 1; session <= pomodoroConfig.Sessions; session++ {
|
||||
shared.Message.Session = session
|
||||
shared.Message.Mode = "Work"
|
||||
if !startTimer(config.Work) {
|
||||
if !startTimer(pomodoroConfig.Work) {
|
||||
break
|
||||
}
|
||||
if session == config.Sessions {
|
||||
if session == pomodoroConfig.Sessions {
|
||||
shared.Message.Mode = "LongBreak"
|
||||
if !startTimer(config.LongBreak) {
|
||||
if !startTimer(pomodoroConfig.LongBreak) {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
shared.Message.Mode = "ShortBreak"
|
||||
if !startTimer(config.ShortBreak) {
|
||||
if !startTimer(pomodoroConfig.ShortBreak) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
var pomodoroConfig = shared.DefaultPomodoroConfig
|
||||
|
||||
// handleClientCommands listens for commands from WebSocket clients
|
||||
func handleClientCommands(ws *websocket.Conn) {
|
||||
for {
|
||||
|
@ -35,10 +33,7 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
switch clientCommand.Command {
|
||||
case "start":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
if clientCommand.Config != shared.UnsetPomodoroConfig {
|
||||
pomodoroConfig = clientCommand.Config
|
||||
}
|
||||
go pomodoro.RunPomodoro(pomodoroConfig) // Start the timer with the list of clients
|
||||
go pomodoro.RunPomodoro() // Start the timer with the list of clients
|
||||
}
|
||||
case "stop":
|
||||
if pomodoro.IsPomodoroOngoing() {
|
||||
|
@ -52,6 +47,14 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
if pomodoro.IsPomodoroOngoing() && pomodoro.IsPomodoroPaused() {
|
||||
pomodoro.ResumePomodoro() // Resume the timer
|
||||
}
|
||||
case "updateSettings":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
if clientCommand.PomodoroSettings != shared.UnsetPomodoroConfig {
|
||||
shared.Message.PomodoroSettings = clientCommand.PomodoroSettings
|
||||
shared.Message.TimeLeft = clientCommand.PomodoroSettings.Work
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue