feat: refactor shared.Message to a channel
- remove `shared` package and shared.Message - rename `notifications` package to `frontend` - introduce a channel send the received ServerMessages to the frontend handler(s) - move keyhandler to goroutine - simplify password handling in Start function - update import names when importing from GoTomoto
This commit is contained in:
parent
cc24dd6775
commit
bbc9977f1c
10 changed files with 108 additions and 82 deletions
|
@ -4,19 +4,19 @@ 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/shared"
|
||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
|
||||
|
||||
"atomicgo.dev/keyboard"
|
||||
"atomicgo.dev/keyboard/keys"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
func Start() {
|
||||
cursor.Hide()
|
||||
defer cursor.Show()
|
||||
|
||||
channel := make(chan GoTomato.ServerMessage, 2)
|
||||
|
||||
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)")
|
||||
|
@ -29,50 +29,14 @@ func Start() {
|
|||
url = config.URL
|
||||
}
|
||||
|
||||
password := *parameter_password
|
||||
if password == "" {
|
||||
password = config.Password
|
||||
if *parameter_password != "" {
|
||||
config.Password = *parameter_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
|
||||
})
|
||||
go websocket.ProcessServerMessages(conn, channel)
|
||||
frontend.Handler(conn, config, channel)
|
||||
|
||||
websocket.Disconnect(conn)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue