ChronoTomato/internal/frontend/main.go

36 lines
909 B
Go

package frontend
import (
"github.com/eiannone/keyboard"
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
// Update the terminal and send desktop notifications until the websocket if closed or "quit"
func UpdateLoop(client websocket.Client, config ChronoTomato.Config, channel <-chan GoTomato.ServerMessage) {
var message GoTomato.ServerMessage
// listen for key events
keysEvents, _ := keyboard.GetKeys(1)
defer keyboard.Close()
for {
select {
case message = <-channel:
// for every received message
desktopNotifications(message)
terminalOutput(message)
case keypress := <-keysEvents:
// react to key pressed
if !menuHandler(keypress, client, config, message) {
return
}
case <-websocket.Done:
// connection closed
return
}
}
}