ChronoTomato/internal/frontend/main.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

32 lines
727 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 UpdateLoop(conn *ws.Conn, config ChronoTomato.Config, channel <-chan GoTomato.ServerMessage) {
var message GoTomato.ServerMessage
keysEvents, _ := keyboard.GetKeys(1)
defer keyboard.Close()
for {
select {
case message = <-channel:
desktopNotifications(message)
terminalOutput(message)
case keypress := <-keysEvents:
if !keyhandler(keypress, conn, config, message) {
return
}
case <-websocket.Done:
return
}
}
}