2024-10-22 11:13:41 +00:00
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
|
|
|
"github.com/charmbracelet/log"
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
)
|
|
|
|
|
|
|
|
func sendClientCommand(conn *websocket.Conn, msg models.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-23 11:18:33 +00:00
|
|
|
func SendCmd(conn *websocket.Conn, pwd string, cmd string) {
|
2024-10-22 11:13:41 +00:00
|
|
|
message := models.ClientCommand{
|
|
|
|
Command: cmd,
|
|
|
|
Password: pwd,
|
|
|
|
}
|
|
|
|
|
|
|
|
sendClientCommand(conn, message)
|
|
|
|
}
|
|
|
|
|
2024-10-23 15:36:30 +00:00
|
|
|
func Send_updateSettings(conn *websocket.Conn, pwd string, settings models.GoTomatoPomodoroConfig) {
|
2024-10-22 11:13:41 +00:00
|
|
|
message := models.ClientCommand{
|
|
|
|
Command: "updateSettings",
|
|
|
|
Password: pwd,
|
2024-10-23 15:36:30 +00:00
|
|
|
PomodoroSettings: settings,
|
2024-10-22 11:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sendClientCommand(conn, message)
|
|
|
|
}
|