From 3a6be4c1870fdefc783e4dbbe94ff856f73df95e Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Mon, 28 Oct 2024 09:30:00 +0100 Subject: [PATCH] feat: update settings handling for pomodoro configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add `UpdateSettings()` to update pomodoro configuration - refactor client command handling to use `UpdateSettings()` 🤖 --- internal/pomodoro/pomodoro.go | 8 ++++++++ internal/websocket/client_commands.go | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index be39e6e..c24d4a5 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -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 + } +} diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index cafcd67..c1f323f 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -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) } } }