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-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-23 16:15:26 +00:00
|
|
|
cursor.Hide()
|
|
|
|
defer cursor.Show()
|
|
|
|
|
2024-10-27 16:01:23 +00:00
|
|
|
// read cli parameters if no config file passed
|
|
|
|
if *configfile == "" {
|
|
|
|
config.URL = *parameter_url
|
|
|
|
config.Password = *parameter_password
|
|
|
|
} else {
|
|
|
|
// otherwise read config
|
2024-10-27 15:36:14 +00:00
|
|
|
config = helper.ParseConfig(*configfile)
|
2024-10-23 15:36:30 +00:00
|
|
|
}
|
|
|
|
|
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-29 17:13:02 +00:00
|
|
|
channel := make(chan GoTomato.ServerMessage)
|
2024-10-30 07:28:22 +00:00
|
|
|
go websocket.ProcessServerMessages(client, channel)
|
|
|
|
frontend.UpdateLoop(client, config, channel)
|
2024-10-23 11:16:30 +00:00
|
|
|
|
2024-10-30 07:28:22 +00:00
|
|
|
websocket.Disconnect(client)
|
2024-10-22 11:13:41 +00:00
|
|
|
}
|