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.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() {

View file

@ -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,
}
}