Compare commits

..

2 commits

Author SHA1 Message Date
bf2685a055 fix: send correct server message on pomodoro end
- replace manual state reset with a dedicated ResetToDefault function
- remove locking mechanism during state updates

🤖
2024-10-21 13:42:32 +02:00
b7d03aa1d8 break: empty Message.Mode when no pomodoro ongoing
- change "none" to an empty string for the mode field
- update README to reflect the new mode representation
- ensure consistency across session end/reset and welcome messages

🤖
2024-10-21 13:14:26 +02:00
3 changed files with 16 additions and 24 deletions

View file

@ -53,7 +53,7 @@ Example:
The server periodically (every second) sends JSON-encoded messages to all connected clients to update them on the current state of the Pomodoro session. The server periodically (every second) sends JSON-encoded messages to all connected clients to update them on the current state of the Pomodoro session.
These messages contain the following fields: These messages contain the following fields:
- mode: Indicates the current phase of the Pomodoro session ("Work", "ShortBreak", "LongBreak", or "none" if no session is running). - mode: Indicates the current phase of the Pomodoro session ("Work", "ShortBreak", "LongBreak", or empty if no session is running).
- session: The current session number (e.g., 1 for the first work session). - session: The current session number (e.g., 1 for the first work session).
- total_sessions: The total number of sessions for the current Pomodoro cycle (e.g., 4 if the cycle consists of 4 work/break sessions). - total_sessions: The total number of sessions for the current Pomodoro cycle (e.g., 4 if the cycle consists of 4 work/break sessions).
- time_left: The remaining time for the current mode, in seconds (e.g., 900 for 15 minutes). - time_left: The remaining time for the current mode, in seconds (e.g., 900 for 15 minutes).
@ -62,11 +62,11 @@ These messages contain the following fields:
| Message Type | Example | | Message Type | Example |
| --------------------- | --------------------------------------------------- | | --------------------- | --------------------------------------------------- |
| Welcome Message | `{"mode": "none", "session":0, "total_sessions":0, "time_left":0, "ongoing": false, "paused": false}` | | Welcome Message | `{"mode": "", "session":0, "total_sessions":0, "time_left":0, "ongoing": false, "paused": false}` |
| Session Running | `{"mode": "Work", "session": 1, "total_sessions": 4, "time_left": 900, "ongoing": true, "paused": false}` | | Session Running | `{"mode": "Work", "session": 1, "total_sessions": 4, "time_left": 900, "ongoing": true, "paused": false}` |
| Session Running | `{"mode": "ShortBreak", "session": 2, "total_sessions": 4, "time_left": 50, "ongoing": true, "paused": false}` | | Session Running | `{"mode": "ShortBreak", "session": 2, "total_sessions": 4, "time_left": 50, "ongoing": true, "paused": false}` |
| Session Paused | `{"mode": "Work", "session": 2, "total_sessions": 4, "time_left": 456, "ongoing": true, "paused": true}` | | Session Paused | `{"mode": "Work", "session": 2, "total_sessions": 4, "time_left": 456, "ongoing": true, "paused": true}` |
| Session End/Reset | `{"mode": "none", "session": 0, "total_sessions": 0, "time_left": 0, "ongoing": false, "paused": false}` | | Session End/Reset | `{"mode": "", "session": 0, "total_sessions": 0, "time_left": 0, "ongoing": false, "paused": false}` |
## Testing ## Testing

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 = "none"
shared.Message.Session = 0
shared.Message.TotalSession = 0
shared.Message.TimeLeft = 0
} }
func PausePomodoro() { func PausePomodoro() {

View file

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