ChronoTomato/internal/websocket/send.go
Sebastian Mark 0f8fde3143 fix: update GoTomato model field names
adjust field names due to breaking changes in GoTomato v0.0.4
2024-10-28 07:56:37 +01:00

42 lines
911 B
Go

package websocket
import (
"encoding/json"
"github.com/charmbracelet/log"
"github.com/gorilla/websocket"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
func sendClientCommand(conn *websocket.Conn, msg GoTomato.ClientCommand) {
messageBytes, err := json.Marshal(msg)
if err != nil {
log.Error("Error marshalling!", "reason", err)
return
}
err = conn.WriteMessage(websocket.TextMessage, messageBytes)
if err != nil {
log.Error("Write error!", "reason", err)
return
}
}
func SendCmd(conn *websocket.Conn, pwd string, cmd string) {
message := GoTomato.ClientCommand{
Command: cmd,
Password: pwd,
}
sendClientCommand(conn, message)
}
func Send_updateSettings(conn *websocket.Conn, pwd string, settings GoTomato.PomodoroConfig) {
message := GoTomato.ClientCommand{
Command: "updateSettings",
Password: pwd,
Settings: settings,
}
sendClientCommand(conn, message)
}