feat: update settings handling for pomodoro configuration

- add `UpdateSettings()` to update pomodoro configuration
- refactor client command handling to use `UpdateSettings()`

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

View file

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