feat: add configuration file handling
- add helper function to parse configuration from a YAML file
- update command-line parameters to include a config file option
- remove hardcoded Pomodoro settings and use parsed config instead
- delete obsolete PomodoroSettings.go file
🤖
This commit is contained in:
parent
25e939f523
commit
bb790459c1
7 changed files with 69 additions and 26 deletions
|
@ -5,10 +5,13 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
|
||||
"ChronoTomato/internal/helper"
|
||||
"ChronoTomato/internal/shared"
|
||||
"ChronoTomato/internal/websocket"
|
||||
|
||||
"atomicgo.dev/keyboard"
|
||||
"atomicgo.dev/keyboard/keys"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
var interrupt = make(chan os.Signal, 1)
|
||||
|
@ -16,16 +19,27 @@ var interrupt = make(chan os.Signal, 1)
|
|||
func Start() {
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
|
||||
GoTomatoUrl := flag.String("url", "ws://localhost:8080/ws", "GoTomato Server URL")
|
||||
password := flag.String("password", "", "Control password for pomodoro session (optional)")
|
||||
autoStart := flag.Bool("start", false, "Immediately start a Pomodoro")
|
||||
parameter_url := flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)")
|
||||
parameter_password := flag.String("password", "", "Control password for pomodoro session (optional)")
|
||||
configfile := flag.String("config", "~/.config/ChronoTomato.yml", "path to config file (optional)")
|
||||
flag.Parse()
|
||||
|
||||
conn := websocket.Connect(*GoTomatoUrl)
|
||||
config := helper.ParseConfig(*configfile)
|
||||
|
||||
websocket.Send_updateSettings(conn, *password)
|
||||
if *autoStart {
|
||||
websocket.SendCmd(conn, *password, "start")
|
||||
url := *parameter_url
|
||||
if url == "" {
|
||||
url = config.URL
|
||||
}
|
||||
|
||||
password := *parameter_password
|
||||
if password == "" {
|
||||
password = config.Password
|
||||
}
|
||||
|
||||
conn := websocket.Connect(url)
|
||||
|
||||
if config.PomodoroConfig != (models.GoTomatoPomodoroConfig{}) {
|
||||
websocket.Send_updateSettings(conn, config.Password, config.PomodoroConfig)
|
||||
}
|
||||
|
||||
go websocket.ProcessServerMessages(conn)
|
||||
|
@ -35,18 +49,18 @@ func Start() {
|
|||
switch key.String() {
|
||||
case "space":
|
||||
if !pomodoro.Ongoing {
|
||||
websocket.SendCmd(conn, *password, "start")
|
||||
websocket.SendCmd(conn, password, "start")
|
||||
return false, nil
|
||||
}
|
||||
if pomodoro.Paused {
|
||||
websocket.SendCmd(conn, *password, "resume")
|
||||
websocket.SendCmd(conn, password, "resume")
|
||||
return false, nil
|
||||
} else {
|
||||
websocket.SendCmd(conn, *password, "pause")
|
||||
websocket.SendCmd(conn, password, "pause")
|
||||
return false, nil
|
||||
}
|
||||
case "r":
|
||||
websocket.SendCmd(conn, *password, "stop")
|
||||
websocket.SendCmd(conn, password, "stop")
|
||||
return false, nil
|
||||
case "q":
|
||||
interrupt <- os.Interrupt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue