ChronoTomato/internal/websocket/receive.go

37 lines
700 B
Go
Raw Normal View History

2024-10-22 11:13:41 +00:00
package websocket
import (
"git.smsvc.net/pomodoro/ChronoTomato/internal/notifications"
"git.smsvc.net/pomodoro/ChronoTomato/internal/shared"
2024-10-22 11:13:41 +00:00
"encoding/json"
"fmt"
"github.com/charmbracelet/log"
"github.com/gorilla/websocket"
)
var Done = make(chan struct{})
func ProcessServerMessages(conn *websocket.Conn) {
defer close(Done)
for {
_, message, err := conn.ReadMessage()
if err != nil {
fmt.Println()
log.Error("Read error!", "reason", err)
return
}
err = json.Unmarshal(message, &shared.ServerMessage)
2024-10-22 11:13:41 +00:00
if err != nil {
log.Error("Error unmarshalling!", "reason", err)
continue
}
notifications.DesktopNotifications()
notifications.TerminalOutput()
2024-10-22 11:13:41 +00:00
}
}