Sebastian Mark
480f1c0cdd
- add default config file
- read passed config file or use default if none provided
- ensure cli parameters always supersede config file settings
- add function to check if a file exists
🤖
56 lines
1.4 KiB
Go
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 websocket.ProcessServerMessages(client, channel)
|
|
frontend.UpdateLoop(client, config, channel)
|
|
|
|
websocket.Disconnect(client)
|
|
}
|