break: enhance server message structure and settings
- add explicit server messages for start and end
- include pomodoro setttings in server messages
- update README
🤖
This commit is contained in:
parent
b60df1c025
commit
a0dba673a2
5 changed files with 35 additions and 28 deletions
29
README.md
29
README.md
|
@ -55,23 +55,26 @@ Example:
|
|||
|
||||
### Server Messages
|
||||
|
||||
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:
|
||||
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:
|
||||
|
||||
- mode: Indicates the current phase of the Pomodoro session ("Work", "ShortBreak", "LongBreak", or empty if no session is running).
|
||||
- mode: Indicates the current phase of the Pomodoro session ("Work", "ShortBreak", "LongBreak", "End" or "Idle").
|
||||
- settings: Contains the current Pomodoro settings:
|
||||
- work: Length of the work session in seconds (e.g., 1500 for 25 minutes).
|
||||
- shortBreak: Length of the short break in seconds (e.g., 300 for 5 minutes).
|
||||
- longBreak: Length of the long break in seconds (e.g., 900 for 15 minutes).
|
||||
- sessions: The total number of work/break sessions (e.g., 4).
|
||||
- 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).
|
||||
- time_left: The remaining time for the current mode, in seconds (e.g., 900 for 15 minutes).
|
||||
- ongoing: Wether a pomodoro is currently ongoing
|
||||
- paused: Wether the timer is paused
|
||||
- ongoing: Whether a Pomodoro session is currently ongoing.
|
||||
- paused: Whether the timer is paused.
|
||||
|
||||
| Message Type | Example |
|
||||
| --------------------- | --------------------------------------------------- |
|
||||
| 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": "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 End/Reset | `{"mode": "", "session": 0, "total_sessions": 0, "time_left": 0, "ongoing": false, "paused": false}` |
|
||||
| Message Type | Example |
|
||||
| --- | --- |
|
||||
| Welcome Message | {"mode":"Idle", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":1500, "ongoing":false, "paused":false} |
|
||||
| Session Running | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":1, "time_left":900, "ongoing":true, "paused":false} |
|
||||
| Session Running | {"mode":"ShortBreak", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":50, "ongoing":true, "paused":false} |
|
||||
| Session Paused | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":456, "ongoing":true, "paused":true} |
|
||||
| Session End/Reset | {"mode":"End", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":0, "ongoing":false, "paused":false} |
|
||||
|
||||
## Testing
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
var data = JSON.parse(event.data);
|
||||
var mode = data.mode;
|
||||
var session = data.session;
|
||||
var totalSession = data.total_sessions;
|
||||
var totalSession = data.settings.sessions;
|
||||
var timeLeft = data.time_left;
|
||||
|
||||
document.getElementById("timer").innerText =
|
||||
|
|
|
@ -19,7 +19,7 @@ func RunPomodoro(config models.GoTomatoPomodoroConfig) {
|
|||
shared.Message.Paused = false
|
||||
mu.Unlock()
|
||||
|
||||
shared.Message.TotalSession = config.Sessions
|
||||
shared.Message.PomodoroSettings = config
|
||||
|
||||
for session := 1; session <= config.Sessions; session++ {
|
||||
shared.Message.Session = session
|
||||
|
@ -38,9 +38,13 @@ func RunPomodoro(config models.GoTomatoPomodoroConfig) {
|
|||
break
|
||||
}
|
||||
}
|
||||
shared.Message.Mode = "End"
|
||||
}
|
||||
|
||||
shared.Message = shared.ResetToDefault()
|
||||
mu.Lock()
|
||||
shared.Message.Ongoing = false
|
||||
shared.Message.Paused = false
|
||||
mu.Unlock()
|
||||
}
|
||||
|
||||
// ResetPomodoro resets the running Pomodoro timer.
|
||||
|
|
|
@ -8,12 +8,12 @@ var Message = ResetToDefault()
|
|||
|
||||
func ResetToDefault() models.ServerMessage {
|
||||
return models.ServerMessage{
|
||||
Mode: "",
|
||||
Session: 0,
|
||||
TotalSession: 0,
|
||||
TimeLeft: 0,
|
||||
Ongoing: false,
|
||||
Paused: false,
|
||||
Mode: "Idle",
|
||||
PomodoroSettings: DefaultPomodoroConfig,
|
||||
Session: 0,
|
||||
TimeLeft: DefaultPomodoroConfig.Work,
|
||||
Ongoing: false,
|
||||
Paused: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ package models
|
|||
|
||||
// ServerMessage represents the data sent to the client via WebSocket.
|
||||
type ServerMessage struct {
|
||||
Mode string `json:"mode"` // "Work", "ShortBreak", or "LongBreak"
|
||||
Session int `json:"session"` // Current session number
|
||||
TotalSession int `json:"total_sessions"` // Total number of sessions
|
||||
TimeLeft int `json:"time_left"` // Remaining time in seconds
|
||||
Ongoing bool `json:"ongoing"` // Ongoing pomodoro
|
||||
Paused bool `json:"paused"` // Is timer paused
|
||||
Mode string `json:"mode"` // "Idle", "Work", "ShortBreak", "LongBreak" or "End"
|
||||
PomodoroSettings GoTomatoPomodoroConfig `json:"settings"` // The currrent pomodoro settings
|
||||
Session int `json:"session"` // Current session number
|
||||
TimeLeft int `json:"time_left"` // Remaining time in seconds
|
||||
Ongoing bool `json:"ongoing"` // Ongoing pomodoro
|
||||
Paused bool `json:"paused"` // Is timer paused
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue