ChronoTomato/internal/websocket/receive.go
Sebastian Mark 4dcc984784 feat: add keyboard controls
- add keyboard listener for space, r, and q keys
- create shared state for server messages
- update desktop and terminal notifications to use shared state

🤖
2024-10-23 17:43:47 +02:00

36 lines
654 B
Go

package websocket
import (
"ChronoTomato/internal/notifications"
"ChronoTomato/internal/shared"
"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)
if err != nil {
log.Error("Error unmarshalling!", "reason", err)
continue
}
notifications.DesktopNotifications()
notifications.TerminalOutput()
}
}