From 03ab627729d44a49515b7ee7662054684ff21234 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Mon, 21 Oct 2024 09:34:36 +0200 Subject: [PATCH] feat: simplify timer function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove "mode" parameter from startTimer function - update shared.Message.Mode for each pomodoro state - update comments 🤖 --- internal/pomodoro/pomodoro.go | 9 ++++++--- internal/pomodoro/timer.go | 7 +++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index b748d0a..c5e927e 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -23,15 +23,18 @@ func RunPomodoro(config models.GoTomatoPomodoroConfig) { for session := 1; session <= config.Sessions; session++ { shared.Message.Session = session - if !startTimer(config.Work, "Work") { + shared.Message.Mode = "Work" + if !startTimer(config.Work) { break } if session == config.Sessions { - if !startTimer(config.LongBreak, "LongBreak") { + shared.Message.Mode = "LongBreak" + if !startTimer(config.LongBreak) { break } } else { - if !startTimer(config.ShortBreak, "ShortBreak") { + shared.Message.Mode = "ShortBreak" + if !startTimer(config.ShortBreak) { break } } diff --git a/internal/pomodoro/timer.go b/internal/pomodoro/timer.go index 1c1f360..4b4c86e 100644 --- a/internal/pomodoro/timer.go +++ b/internal/pomodoro/timer.go @@ -5,8 +5,8 @@ import ( "time" ) -// startTimer runs the countdown and shared. every second. -func startTimer(remainingSeconds int, mode string) bool { +// runs the countdown and updates shared.Message.TimeLeft every second. +func startTimer(remainingSeconds int) bool { for remainingSeconds > 0 { select { case <-pomodoroResetChannel: @@ -18,7 +18,6 @@ func startTimer(remainingSeconds int, mode string) bool { default: // Broadcast the current state to all clients if !IsPomodoroPaused() { - shared.Message.Mode = mode shared.Message.TimeLeft = remainingSeconds time.Sleep(time.Second) remainingSeconds-- @@ -26,7 +25,7 @@ func startTimer(remainingSeconds int, mode string) bool { } } - // Final shared.when time reaches zero + // Final shared.Message when time reaches zero shared.Message.TimeLeft = remainingSeconds return true