60 lines
1.5 KiB
Go
60 lines
1.5 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()
|
|
|
|
// 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
|
|
}
|
|
|
|
// Create a client
|
|
client := websocket.Connect(config.URL)
|
|
client.Password = config.Password
|
|
|
|
// Receive server messages und update the terminal
|
|
channel := make(chan GoTomato.ServerMessage)
|
|
go client.ProcessServerMessages(channel)
|
|
frontend.UpdateLoop(client, config, channel)
|
|
|
|
// disconnect from server
|
|
client.Disconnect()
|
|
}
|