Sebastian Mark
bb790459c1
- add helper function to parse configuration from a YAML file
- update command-line parameters to include a config file option
- remove hardcoded Pomodoro settings and use parsed config instead
- delete obsolete PomodoroSettings.go file
🤖
42 lines
926 B
Go
42 lines
926 B
Go
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
|
|
}
|
|
}
|
|
|
|
func SendCmd(conn *websocket.Conn, pwd string, cmd string) {
|
|
message := models.ClientCommand{
|
|
Command: cmd,
|
|
Password: pwd,
|
|
}
|
|
|
|
sendClientCommand(conn, message)
|
|
}
|
|
|
|
func Send_updateSettings(conn *websocket.Conn, pwd string, settings models.GoTomatoPomodoroConfig) {
|
|
message := models.ClientCommand{
|
|
Command: "updateSettings",
|
|
Password: pwd,
|
|
PomodoroSettings: settings,
|
|
}
|
|
|
|
sendClientCommand(conn, message)
|
|
}
|