Sebastian Mark
0ca90b50a5
- 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
🤖
31 lines
704 B
Go
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
|
|
}
|
|
}
|
|
}
|