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
🤖
38 lines
920 B
Go
38 lines
920 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 start_pause_resume(message GoTomato.ServerMessage) string {
|
|
if !message.Ongoing {
|
|
return "start"
|
|
}
|
|
if message.Paused {
|
|
return "resume"
|
|
} else {
|
|
return "pause"
|
|
}
|
|
}
|
|
|
|
func keyhandler(key keyboard.KeyEvent, client websocket.Client, config ChronoTomato.Config, message GoTomato.ServerMessage) bool {
|
|
switch key.Rune {
|
|
case 0: // space
|
|
cmd := start_pause_resume(message)
|
|
client.SendCmd(config.Password, cmd)
|
|
case 115: // s
|
|
client.SendCmd(config.Password, "stop")
|
|
case 114: // r
|
|
if config.PomodoroConfig != (GoTomato.PomodoroConfig{}) {
|
|
client.SendSettingsUpdate(config.Password, config.PomodoroConfig)
|
|
}
|
|
case 113: // q
|
|
return false
|
|
}
|
|
return true
|
|
}
|