This commit is contained in:
Sebastian Mark 2024-10-22 13:13:41 +02:00
commit 11c599a371
11 changed files with 325 additions and 0 deletions

View file

@ -0,0 +1,37 @@
package websocket
import (
"ChronoTomato/internal/notifications"
"encoding/json"
"fmt"
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
"github.com/charmbracelet/log"
"github.com/gorilla/websocket"
)
var Done = make(chan struct{})
func ProcessServerMessages(conn *websocket.Conn) {
var serverMessage models.ServerMessage
defer close(Done)
for {
_, message, err := conn.ReadMessage()
if err != nil {
fmt.Println()
log.Error("Read error!", "reason", err)
return
}
err = json.Unmarshal(message, &serverMessage)
if err != nil {
log.Error("Error unmarshalling!", "reason", err)
continue
}
notifications.DesktopNotifications(serverMessage)
notifications.TerminalOutput(serverMessage)
}
}