diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index 6b83842..9eeb04c 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -18,7 +18,7 @@ func waitForTimer(t Timer) bool { return true case <-t.Abort: return false - case shared.Message.TimeLeft = <-t.TimeLeft: + case shared.State.TimeLeft = <-t.TimeLeft: // do nothing, just let the timer update the message } } @@ -27,48 +27,48 @@ func waitForTimer(t Timer) bool { // RunPomodoro iterates the Pomodoro work/break sessions. func RunPomodoro() { mu.Lock() - shared.Message.Ongoing = true - shared.Message.Paused = false + shared.State.Ongoing = true + shared.State.Paused = false mu.Unlock() - pomodoroConfig := shared.Message.Settings + pomodoroConfig := shared.State.Settings for session := 1; session <= pomodoroConfig.Sessions; session++ { timer = timer.Init() - shared.Message.Session = session + shared.State.Session = session - shared.Message.Mode = "Work" + shared.State.Mode = "Work" go timer.Start(pomodoroConfig.Work) if !waitForTimer(timer) { break } if session < pomodoroConfig.Sessions { - shared.Message.Mode = "ShortBreak" + shared.State.Mode = "ShortBreak" go timer.Start(pomodoroConfig.ShortBreak) if !waitForTimer(timer) { break } } else { // last phase, prepare for finish - shared.Message.Mode = "LongBreak" + shared.State.Mode = "LongBreak" go timer.Start(pomodoroConfig.LongBreak) if !waitForTimer(timer) { break } - shared.Message.Mode = "End" + shared.State.Mode = "End" time.Sleep(time.Second) } } mu.Lock() - shared.Message.Ongoing = false - shared.Message.Paused = false + shared.State.Ongoing = false + shared.State.Paused = false mu.Unlock() - shared.Message.Mode = "Idle" - shared.Message.Session = 0 - shared.Message.TimeLeft = shared.Message.Settings.Work + shared.State.Mode = "Idle" + shared.State.Session = 0 + shared.State.TimeLeft = shared.State.Settings.Work } func ResetPomodoro() { @@ -77,7 +77,7 @@ func ResetPomodoro() { func PausePomodoro() { mu.Lock() - shared.Message.Paused = true + shared.State.Paused = true mu.Unlock() timer.Pause() @@ -85,7 +85,7 @@ func PausePomodoro() { func ResumePomodoro() { mu.Lock() - shared.Message.Paused = false + shared.State.Paused = false mu.Unlock() timer.Resume() } @@ -93,18 +93,18 @@ func ResumePomodoro() { func IsPomodoroOngoing() bool { mu.Lock() defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done - return shared.Message.Ongoing + return shared.State.Ongoing } func IsPomodoroPaused() bool { mu.Lock() defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done - return shared.Message.Paused + return shared.State.Paused } func UpdateSettings(settings models.PomodoroConfig) { if settings != (models.PomodoroConfig{}) { - shared.Message.Settings = settings - shared.Message.TimeLeft = settings.Work + shared.State.Settings = settings + shared.State.TimeLeft = settings.Work } } diff --git a/internal/shared/state.go b/internal/shared/state.go index a9eac1b..a6e1829 100644 --- a/internal/shared/state.go +++ b/internal/shared/state.go @@ -5,7 +5,7 @@ import ( "git.smsvc.net/pomodoro/GoTomato/pkg/models" ) -var Message = models.ServerMessage{ +var State = models.ServerMessage{ Mode: "Idle", Settings: DefaultPomodoroConfig, Session: 0, diff --git a/internal/websocket/broadcast.go b/internal/websocket/broadcast.go index 64b8fb4..d0e5f67 100644 --- a/internal/websocket/broadcast.go +++ b/internal/websocket/broadcast.go @@ -14,7 +14,7 @@ func SendPermanentBroadCastMessage() { tick := time.NewTicker(time.Second) for { // Marshal the message into JSON format - jsonMessage, err := json.Marshal(shared.Message) + jsonMessage, err := json.Marshal(shared.State) if err != nil { log.Error("Error marshalling message:", "msg", err) return