ChronoTomato/internal/frontend/keyhandler.go
Sebastian Mark f1071f33c6 feat: update keyboard handling to use new library
- remove dependency on atomicgo.dev/keyboard
- add dependency on github.com/eiannone/keyboard
- include keyhandling as non-blocking in frondend/main
- refactor keyhandler()

🤖
2024-10-29 20:22:22 +01:00

39 lines
973 B
Go

package frontend
import (
"github.com/eiannone/keyboard"
ws "github.com/gorilla/websocket"
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
func start_pause_resume(message GoTomato.ServerMessage) string {
if !message.Ongoing {
return "start"
}
if message.Paused {
return "resume"
} else {
return "pause"
}
}
func keyhandler(key keyboard.KeyEvent, conn *ws.Conn, config ChronoTomato.Config, message GoTomato.ServerMessage) bool {
switch key.Rune {
case 0: // space
cmd := start_pause_resume(message)
websocket.SendCmd(conn, config.Password, cmd)
case 115: // s
websocket.SendCmd(conn, config.Password, "stop")
case 114: // r
if config.PomodoroConfig != (GoTomato.PomodoroConfig{}) {
websocket.Send_updateSettings(conn, config.Password, config.PomodoroConfig)
}
case 113: // q
return false
}
return true
}