ChronoTomato/internal/frontend/main.go
Sebastian Mark 0ca90b50a5 feat: refactor client handling and introduce websocket client type
- add new websocket.Client type
- change Connect and Disconnect functions to use the new Client type
- implement methods for sending commands and updating settings on Client
- update keyhandler to use websocket.Client instead of ChronoTomato.Client
- modify UpdateLoop to accept websocket.Client
- refactor ProcessServerMessages to accept the new Client type

🤖
2024-10-30 08:57:10 +01:00

31 lines
704 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"
)
func UpdateLoop(client websocket.Client, 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, client, config, message) {
return
}
case <-websocket.Done:
return
}
}
}