feat: update settings handling for pomodoro configuration

- add UpdateSettings function to manage pomodoro configuration
- refactor client command handling to use UpdateSettings function

🤖
This commit is contained in:
Sebastian Mark 2024-10-28 09:30:00 +01:00
parent 1a47c0607b
commit 75fda61f48
2 changed files with 9 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package pomodoro
import ( import (
"git.smsvc.net/pomodoro/GoTomato/internal/shared" "git.smsvc.net/pomodoro/GoTomato/internal/shared"
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
"sync" "sync"
"time" "time"
) )
@ -99,3 +100,10 @@ func IsPomodoroPaused() bool {
defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done
return shared.Message.Paused return shared.Message.Paused
} }
func UpdateSettings(settings models.PomodoroConfig) {
if settings != (models.PomodoroConfig{}) {
shared.Message.Settings = settings
shared.Message.TimeLeft = settings.Work
}
}

View file

@ -49,11 +49,7 @@ func handleClientCommands(ws *websocket.Conn) {
} }
case "updateSettings": case "updateSettings":
if !pomodoro.IsPomodoroOngoing() { if !pomodoro.IsPomodoroOngoing() {
if clientCommand.Settings != (models.PomodoroConfig{}) { pomodoro.UpdateSettings(clientCommand.Settings)
shared.Message.Settings = clientCommand.Settings
shared.Message.TimeLeft = clientCommand.Settings.Work
}
} }
} }
} }