From b46d2469d3dae81c55b33e17363c18db5c96a52c Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sun, 20 Oct 2024 18:08:12 +0200 Subject: [PATCH] feat: update variable and function name for started pomodoro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - change variable name from pomodoroRunning to pomodoroOngoing - update function name from IsPomodoroRunning to IsPomodoroOngoing - modify client command checks to use IsPomodoroActive instead of IsPomodoroRunning 🤖 --- internal/pomodoro/pomodoro.go | 12 ++++++------ internal/websocket/client_commands.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index 5599af7..c030acf 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -14,7 +14,7 @@ var PomodoroConfig = models.GoTomatoTimerConfig{ Sessions: 4, } -var pomodoroRunning bool +var pomodoroOngoing bool var pomodoroPaused bool var pomodoroResetChannel = make(chan bool, 1) @@ -26,7 +26,7 @@ var mu sync.Mutex // to synchronize access to shared state // RunPomodoroTimer iterates the Pomodoro work/break sessions. func RunPomodoroTimer(clients map[*websocket.Conn]*models.Client) { mu.Lock() - pomodoroRunning = true + pomodoroOngoing = true pomodoroPaused = false mu.Unlock() @@ -46,14 +46,14 @@ func RunPomodoroTimer(clients map[*websocket.Conn]*models.Client) { } mu.Lock() - pomodoroRunning = false + pomodoroOngoing = false mu.Unlock() } // ResetPomodoro resets the running Pomodoro timer. func ResetPomodoro(clients map[*websocket.Conn]*models.Client) { mu.Lock() - pomodoroRunning = false // Reset the running state + pomodoroOngoing = false // Reset the running state pomodoroPaused = false // Reset the paused state mu.Unlock() @@ -84,10 +84,10 @@ func ResumePomodoro() { pomodoroResumeChannel <- true } -func IsPomodoroRunning() bool { +func IsPomodoroOngoing() bool { mu.Lock() defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done - return pomodoroRunning + return pomodoroOngoing } func IsPomodoroPaused() bool { diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index acec6b0..c5e5340 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -34,19 +34,19 @@ func handleClientCommands(ws *websocket.Conn) { // Process the command switch command.Command { case "start": - if !pomodoro.IsPomodoroRunning() { + if !pomodoro.IsPomodoroOngoing() { go pomodoro.RunPomodoroTimer(Clients) // Start the timer with the list of clients } case "stop": - if pomodoro.IsPomodoroRunning() { + if pomodoro.IsPomodoroOngoing() { pomodoro.ResetPomodoro(Clients) // Reset Pomodoro } case "pause": - if pomodoro.IsPomodoroRunning() && !pomodoro.IsPomodoroPaused() { + if pomodoro.IsPomodoroOngoing() && !pomodoro.IsPomodoroPaused() { pomodoro.PausePomodoro() // Pause the timer } case "resume": - if pomodoro.IsPomodoroRunning() && pomodoro.IsPomodoroPaused() { + if pomodoro.IsPomodoroOngoing() && pomodoro.IsPomodoroPaused() { pomodoro.ResumePomodoro() // Resume the timer } }