From bf2685a055aecb7626f009e0a8f4e5c37bd8897c Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Mon, 21 Oct 2024 13:42:32 +0200 Subject: [PATCH] fix: send correct server message on pomodoro end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - replace manual state reset with a dedicated ResetToDefault function - remove locking mechanism during state updates 🤖 --- internal/pomodoro/pomodoro.go | 16 ++-------------- internal/shared/state.go | 18 +++++++++++------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index 2c69b65..702d0f7 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -40,26 +40,14 @@ func RunPomodoro(config models.GoTomatoPomodoroConfig) { } } - mu.Lock() - shared.Message.Ongoing = false - mu.Unlock() + shared.Message = shared.ResetToDefault() } // ResetPomodoro resets the running Pomodoro timer. func ResetPomodoro() { // Send a reset signal to stop any running timers pomodoroResetChannel <- true - - mu.Lock() - shared.Message.Ongoing = false - shared.Message.Paused = false - mu.Unlock() - - // Reset message - shared.Message.Mode = "" - shared.Message.Session = 0 - shared.Message.TotalSession = 0 - shared.Message.TimeLeft = 0 + shared.Message = shared.ResetToDefault() } func PausePomodoro() { diff --git a/internal/shared/state.go b/internal/shared/state.go index 3c0ddec..87e8759 100644 --- a/internal/shared/state.go +++ b/internal/shared/state.go @@ -4,11 +4,15 @@ import ( "git.smsvc.net/pomodoro/GoTomato/pkg/models" ) -var Message = models.ServerMessage{ - Mode: "", - Session: 0, - TotalSession: 0, - TimeLeft: 0, - Ongoing: false, - Paused: false, +var Message = ResetToDefault() + +func ResetToDefault() models.ServerMessage { + return models.ServerMessage{ + Mode: "", + Session: 0, + TotalSession: 0, + TimeLeft: 0, + Ongoing: false, + Paused: false, + } }