ChronoTomato/internal/websocket/send.go
Sebastian Mark b374ee8aff feat: add Password field to PomodoroClient struct
remove unused password parameters from Client-Methods

🤖
2024-10-30 09:00:29 +01:00

45 lines
989 B
Go

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