ChronoTomato/cmd/client/main.go
Sebastian Mark b943c9d6eb feat: refactor connection handling to use models.Client
- introduce `Client` model
- modify all websocket operations to use the new `Client` model
- update function signatures to accept `models.Client` instead of `*websocket.Conn`
- ensure consistent usage of `client` across all related functions

🤖
2024-10-30 08:28:22 +01:00

45 lines
1.1 KiB
Go

package client
import (
"atomicgo.dev/cursor"
"flag"
"git.smsvc.net/pomodoro/ChronoTomato/internal/frontend"
"git.smsvc.net/pomodoro/ChronoTomato/internal/helper"
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
var (
config ChronoTomato.Config
parameter_url = flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)")
parameter_password = flag.String("password", "", "Control password for pomodoro session")
configfile = flag.String("config", "", "Path to config file")
)
func Start() {
flag.Parse()
cursor.Hide()
defer cursor.Show()
// read cli parameters if no config file passed
if *configfile == "" {
config.URL = *parameter_url
config.Password = *parameter_password
} else {
// otherwise read config
config = helper.ParseConfig(*configfile)
}
client := websocket.Connect(config.URL)
channel := make(chan GoTomato.ServerMessage)
go websocket.ProcessServerMessages(client, channel)
frontend.UpdateLoop(client, config, channel)
websocket.Disconnect(client)
}