fix: send correct server message on pomodoro end

- replace manual state reset with a dedicated ResetToDefault function
- remove locking mechanism during state updates

🤖
This commit is contained in:
Sebastian Mark 2024-10-21 13:42:32 +02:00
parent b7d03aa1d8
commit bf2685a055
2 changed files with 13 additions and 21 deletions

View file

@ -40,26 +40,14 @@ func RunPomodoro(config models.GoTomatoPomodoroConfig) {
} }
} }
mu.Lock() shared.Message = shared.ResetToDefault()
shared.Message.Ongoing = false
mu.Unlock()
} }
// ResetPomodoro resets the running Pomodoro timer. // ResetPomodoro resets the running Pomodoro timer.
func ResetPomodoro() { func ResetPomodoro() {
// Send a reset signal to stop any running timers // Send a reset signal to stop any running timers
pomodoroResetChannel <- true pomodoroResetChannel <- true
shared.Message = shared.ResetToDefault()
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
} }
func PausePomodoro() { func PausePomodoro() {

View file

@ -4,7 +4,10 @@ import (
"git.smsvc.net/pomodoro/GoTomato/pkg/models" "git.smsvc.net/pomodoro/GoTomato/pkg/models"
) )
var Message = models.ServerMessage{ var Message = ResetToDefault()
func ResetToDefault() models.ServerMessage {
return models.ServerMessage{
Mode: "", Mode: "",
Session: 0, Session: 0,
TotalSession: 0, TotalSession: 0,
@ -12,3 +15,4 @@ var Message = models.ServerMessage{
Ongoing: false, Ongoing: false,
Paused: false, Paused: false,
} }
}