ChronoTomato/cmd/client/main.go
Sebastian Mark 6187122b81 feat: refactor client methods
- change `ProcessServerMessages` to use receiver instead of parameter
- update `Disconnect` method to use receiver for better encapsulation
- move `Client` definition to `connect.go`

🤖
2024-10-30 09:51:59 +01:00

56 lines
1.4 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
defaultConfigFile = "~/.config/ChronoTomato.yml"
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 passed config file or try to use default config
if *configfile != "" {
config = helper.ParseConfig(*configfile)
} else {
if helper.FileExists(defaultConfigFile) {
config = helper.ParseConfig(defaultConfigFile)
}
}
// cli parameters always supersede config file
if *parameter_url != "" {
config.URL = *parameter_url
}
if *parameter_password != "" {
config.Password = *parameter_password
}
client := websocket.Connect(config.URL)
client.Password = config.Password
channel := make(chan GoTomato.ServerMessage)
go client.ProcessServerMessages(channel)
frontend.UpdateLoop(client, config, channel)
client.Disconnect()
}