2024-10-22 11:13:41 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2024-10-23 16:15:26 +00:00
|
|
|
"atomicgo.dev/cursor"
|
2024-10-22 11:13:41 +00:00
|
|
|
"flag"
|
|
|
|
|
2024-10-27 09:41:31 +00:00
|
|
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/frontend"
|
2024-10-23 15:59:46 +00:00
|
|
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/helper"
|
|
|
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
|
2024-10-23 15:36:30 +00:00
|
|
|
|
2024-10-27 15:36:14 +00:00
|
|
|
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
2024-10-27 09:41:31 +00:00
|
|
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
2024-10-22 11:13:41 +00:00
|
|
|
)
|
|
|
|
|
2024-10-27 16:01:23 +00:00
|
|
|
var (
|
2024-10-27 20:32:57 +00:00
|
|
|
config ChronoTomato.Config
|
|
|
|
|
2024-10-30 08:32:01 +00:00
|
|
|
defaultConfigFile = "~/.config/ChronoTomato.yml"
|
|
|
|
|
2024-10-27 16:01:23 +00:00
|
|
|
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() {
|
2024-10-27 16:01:23 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
2024-10-30 10:03:18 +00:00
|
|
|
// show/hide cursor for nicer interface
|
2024-10-23 16:15:26 +00:00
|
|
|
cursor.Hide()
|
|
|
|
defer cursor.Show()
|
|
|
|
|
2024-10-30 08:32:01 +00:00
|
|
|
// 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 != "" {
|
2024-10-27 16:01:23 +00:00
|
|
|
config.URL = *parameter_url
|
2024-10-30 08:32:01 +00:00
|
|
|
}
|
|
|
|
if *parameter_password != "" {
|
2024-10-27 16:01:23 +00:00
|
|
|
config.Password = *parameter_password
|
2024-10-23 15:36:30 +00:00
|
|
|
}
|
|
|
|
|
2024-10-30 10:03:18 +00:00
|
|
|
// Create a client
|
2024-10-30 07:28:22 +00:00
|
|
|
client := websocket.Connect(config.URL)
|
2024-10-30 08:00:29 +00:00
|
|
|
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
|
2024-10-29 17:13:02 +00:00
|
|
|
channel := make(chan GoTomato.ServerMessage)
|
2024-10-30 08:51:59 +00:00
|
|
|
go client.ProcessServerMessages(channel)
|
2024-10-30 07:28:22 +00:00
|
|
|
frontend.UpdateLoop(client, config, channel)
|
2024-10-23 11:16:30 +00:00
|
|
|
|
2024-10-30 10:03:18 +00:00
|
|
|
// disconnect from server
|
2024-10-30 08:51:59 +00:00
|
|
|
client.Disconnect()
|
2024-10-22 11:13:41 +00:00
|
|
|
}
|