ChronoTomato/internal/frontend/main.go

37 lines
909 B
Go
Raw Normal View History

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"
)
2024-10-30 10:03:18 +00:00
// 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
2024-10-30 10:03:18 +00:00
// listen for key events
keysEvents, _ := keyboard.GetKeys(1)
defer keyboard.Close()
for {
select {
case message = <-channel:
2024-10-30 10:03:18 +00:00
// for every received message
desktopNotifications(message)
terminalOutput(message)
case keypress := <-keysEvents:
2024-10-30 10:03:18 +00:00
// react to key pressed
if !menuHandler(keypress, client, config, message) {
return
}
case <-websocket.Done:
2024-10-30 10:03:18 +00:00
// connection closed
return
}
}
}