Sebastian Mark
e14492a01c
- remove os signal handling interrupt
- rename WaitForDisconnect to Disconnect function
- improve websocket disconnection logic
- exit keyboard listener on disconnect
🤖
78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package client
|
|
|
|
import (
|
|
"atomicgo.dev/cursor"
|
|
"flag"
|
|
|
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/helper"
|
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/shared"
|
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
|
|
|
|
"atomicgo.dev/keyboard"
|
|
"atomicgo.dev/keyboard/keys"
|
|
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
|
)
|
|
|
|
func Start() {
|
|
cursor.Hide()
|
|
defer cursor.Show()
|
|
|
|
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()
|
|
|
|
config := helper.ParseConfig(*configfile)
|
|
|
|
url := *parameter_url
|
|
if url == "" {
|
|
url = config.URL
|
|
}
|
|
|
|
password := *parameter_password
|
|
if password == "" {
|
|
password = config.Password
|
|
}
|
|
|
|
conn := websocket.Connect(url)
|
|
|
|
go websocket.ProcessServerMessages(conn)
|
|
|
|
pomodoro := &shared.ServerMessage
|
|
keyboard.Listen(func(key keys.Key) (stop bool, err error) {
|
|
select {
|
|
case <-websocket.Done:
|
|
return true, nil
|
|
default:
|
|
switch key.String() {
|
|
case "space":
|
|
if !pomodoro.Ongoing {
|
|
websocket.SendCmd(conn, password, "start")
|
|
return false, nil
|
|
}
|
|
if pomodoro.Paused {
|
|
websocket.SendCmd(conn, password, "resume")
|
|
return false, nil
|
|
} else {
|
|
websocket.SendCmd(conn, password, "pause")
|
|
return false, nil
|
|
}
|
|
case "s":
|
|
websocket.SendCmd(conn, password, "stop")
|
|
return false, nil
|
|
case "r":
|
|
|
|
if config.PomodoroConfig != (models.GoTomatoPomodoroConfig{}) {
|
|
websocket.Send_updateSettings(conn, password, config.PomodoroConfig)
|
|
}
|
|
return false, nil
|
|
case "q":
|
|
return true, nil
|
|
}
|
|
}
|
|
|
|
return false, nil
|
|
})
|
|
|
|
websocket.Disconnect(conn)
|
|
}
|