ChronoTomato/cmd/client/main.go

61 lines
1.5 KiB
Go
Raw Normal View History

2024-10-22 11:13:41 +00:00
package client
import (
"atomicgo.dev/cursor"
2024-10-22 11:13:41 +00:00
"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"
2024-10-22 11:13:41 +00:00
)
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")
)
2024-10-22 11:13:41 +00:00
func Start() {
flag.Parse()
2024-10-30 10:03:18 +00:00
// show/hide cursor for nicer interface
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
}
2024-10-30 10:03:18 +00:00
// Create a client
client := websocket.Connect(config.URL)
client.Password = config.Password
2024-10-22 11:13:41 +00:00
2024-10-30 10:03:18 +00:00
// Receive server messages und update the terminal
channel := make(chan GoTomato.ServerMessage)
go client.ProcessServerMessages(channel)
frontend.UpdateLoop(client, config, channel)
2024-10-30 10:03:18 +00:00
// disconnect from server
client.Disconnect()
2024-10-22 11:13:41 +00:00
}