ChronoTomato/cmd/client/main.go
Sebastian Mark bbc9977f1c feat: refactor shared.Message to a channel
- remove `shared` package and shared.Message
- rename `notifications` package to `frontend`
- introduce a channel send the received ServerMessages to the frontend handler(s)
- move keyhandler to goroutine
- simplify password handling in Start function
- update import names when importing from GoTomoto
2024-10-27 22:33:30 +01:00

42 lines
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"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
func Start() {
cursor.Hide()
defer cursor.Show()
channel := make(chan GoTomato.ServerMessage, 2)
parameter_url := flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)")
parameter_password := flag.String("password", "", "Control password for pomodoro session (optional)")
configfile := flag.String("config", "~/.config/ChronoTomato.yml", "path to config file (optional)")
flag.Parse()
config := helper.ParseConfig(*configfile)
url := *parameter_url
if url == "" {
url = config.URL
}
if *parameter_password != "" {
config.Password = *parameter_password
}
conn := websocket.Connect(url)
go websocket.ProcessServerMessages(conn, channel)
frontend.Handler(conn, config, channel)
websocket.Disconnect(conn)
}