2024-10-27 09:41:31 +00:00
|
|
|
package frontend
|
|
|
|
|
|
|
|
import (
|
2024-10-29 19:13:39 +00:00
|
|
|
"github.com/eiannone/keyboard"
|
|
|
|
|
|
|
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
|
2024-10-27 20:34:53 +00:00
|
|
|
|
2024-10-27 09:41:31 +00:00
|
|
|
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"
|
2024-10-30 07:54:58 +00:00
|
|
|
func UpdateLoop(client websocket.Client, config ChronoTomato.Config, channel <-chan GoTomato.ServerMessage) {
|
2024-10-27 20:47:05 +00:00
|
|
|
var message GoTomato.ServerMessage
|
|
|
|
|
2024-10-30 10:03:18 +00:00
|
|
|
// listen for key events
|
2024-10-29 19:13:39 +00:00
|
|
|
keysEvents, _ := keyboard.GetKeys(1)
|
|
|
|
defer keyboard.Close()
|
2024-10-27 09:41:31 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case message = <-channel:
|
2024-10-30 10:03:18 +00:00
|
|
|
// for every received message
|
2024-10-27 09:41:31 +00:00
|
|
|
desktopNotifications(message)
|
|
|
|
terminalOutput(message)
|
2024-10-29 19:13:39 +00:00
|
|
|
case keypress := <-keysEvents:
|
2024-10-30 10:03:18 +00:00
|
|
|
// react to key pressed
|
|
|
|
if !menuHandler(keypress, client, config, message) {
|
2024-10-29 19:13:39 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
case <-websocket.Done:
|
2024-10-30 10:03:18 +00:00
|
|
|
// connection closed
|
2024-10-27 09:41:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|