Compare commits

..

No commits in common. "f098c1f6bf745295c87c417bf5ce4a2a0916feba" and "d2e34e84f87f2dfd7e88836a4e30795a6bb3a88e" have entirely different histories.

5 changed files with 9 additions and 9 deletions

View file

@ -8,7 +8,7 @@ import (
) )
// BroadcastMessage sends a message to all connected WebSocket clients. // BroadcastMessage sends a message to all connected WebSocket clients.
func BroadcastMessage(clients map[*websocket.Conn]*models.Client, message models.ServerMessage) { func BroadcastMessage(clients map[*websocket.Conn]*models.Client, message models.BroadcastMessage) {
// Marshal the message into JSON format // Marshal the message into JSON format
jsonMessage, err := json.Marshal(message) jsonMessage, err := json.Marshal(message)
if err != nil { if err != nil {

View file

@ -23,8 +23,8 @@ var pomodoroResumeChannel = make(chan bool, 1)
var mu sync.Mutex // to synchronize access to shared state var mu sync.Mutex // to synchronize access to shared state
// RunPomodoro iterates the Pomodoro work/break sessions. // RunPomodoroTimer iterates the Pomodoro work/break sessions.
func RunPomodoro(clients map[*websocket.Conn]*models.Client) { func RunPomodoroTimer(clients map[*websocket.Conn]*models.Client) {
mu.Lock() mu.Lock()
pomodoroOngoing = true pomodoroOngoing = true
pomodoroPaused = false pomodoroPaused = false
@ -58,7 +58,7 @@ func ResetPomodoro(clients map[*websocket.Conn]*models.Client) {
mu.Unlock() mu.Unlock()
// Broadcast the reset message to all clients // Broadcast the reset message to all clients
broadcast.BroadcastMessage(clients, models.ServerMessage{ broadcast.BroadcastMessage(clients, models.BroadcastMessage{
Mode: "none", Mode: "none",
Session: 0, Session: 0,
MaxSession: 0, MaxSession: 0,

View file

@ -20,7 +20,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
default: default:
// Broadcast the current state to all clients // Broadcast the current state to all clients
if !IsPomodoroPaused() { if !IsPomodoroPaused() {
broadcast.BroadcastMessage(clients, models.ServerMessage{ broadcast.BroadcastMessage(clients, models.BroadcastMessage{
Mode: mode, Mode: mode,
Session: session, Session: session,
MaxSession: PomodoroConfig.Sessions, MaxSession: PomodoroConfig.Sessions,
@ -33,7 +33,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
} }
// Final broadcast when time reaches zero // Final broadcast when time reaches zero
broadcast.BroadcastMessage(clients, models.ServerMessage{ broadcast.BroadcastMessage(clients, models.BroadcastMessage{
Mode: mode, Mode: mode,
Session: session, Session: session,
MaxSession: PomodoroConfig.Sessions, MaxSession: PomodoroConfig.Sessions,

View file

@ -30,7 +30,7 @@ func handleClientCommands(ws *websocket.Conn) {
switch command.Command { switch command.Command {
case "start": case "start":
if !pomodoro.IsPomodoroOngoing() { if !pomodoro.IsPomodoroOngoing() {
go pomodoro.RunPomodoro(Clients) // Start the timer with the list of clients go pomodoro.RunPomodoroTimer(Clients) // Start the timer with the list of clients
} }
case "stop": case "stop":
if pomodoro.IsPomodoroOngoing() { if pomodoro.IsPomodoroOngoing() {

View file

@ -1,7 +1,7 @@
package models package models
// ServerMessage represents the data sent to the client via WebSocket. // BroadcastMessage represents the data sent to the client via WebSocket.
type ServerMessage struct { type BroadcastMessage struct {
Mode string `json:"mode"` // "Work", "ShortBreak", or "LongBreak" Mode string `json:"mode"` // "Work", "ShortBreak", or "LongBreak"
Session int `json:"session"` // Current session number Session int `json:"session"` // Current session number
MaxSession int `json:"max_session"` // Total number of sessions MaxSession int `json:"max_session"` // Total number of sessions