2024-10-27 09:41:31 +00:00
|
|
|
package frontend
|
|
|
|
|
|
|
|
import (
|
2024-10-29 19:13:39 +00:00
|
|
|
"github.com/eiannone/keyboard"
|
2024-10-27 20:34:53 +00:00
|
|
|
ws "github.com/gorilla/websocket"
|
|
|
|
|
2024-10-27 09:41:31 +00:00
|
|
|
"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-29 19:13:39 +00:00
|
|
|
func start_pause_resume(message GoTomato.ServerMessage) string {
|
2024-10-27 20:57:05 +00:00
|
|
|
if !message.Ongoing {
|
|
|
|
return "start"
|
|
|
|
}
|
|
|
|
if message.Paused {
|
|
|
|
return "resume"
|
|
|
|
} else {
|
|
|
|
return "pause"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-29 19:13:39 +00:00
|
|
|
func keyhandler(key keyboard.KeyEvent, conn *ws.Conn, config ChronoTomato.Config, message GoTomato.ServerMessage) bool {
|
|
|
|
switch key.Rune {
|
|
|
|
case 0: // space
|
|
|
|
cmd := start_pause_resume(message)
|
|
|
|
websocket.SendCmd(conn, config.Password, cmd)
|
|
|
|
case 115: // s
|
|
|
|
websocket.SendCmd(conn, config.Password, "stop")
|
|
|
|
case 114: // r
|
|
|
|
if config.PomodoroConfig != (GoTomato.PomodoroConfig{}) {
|
|
|
|
websocket.Send_updateSettings(conn, config.Password, config.PomodoroConfig)
|
2024-10-27 09:41:31 +00:00
|
|
|
}
|
2024-10-29 19:13:39 +00:00
|
|
|
case 113: // q
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2024-10-27 09:41:31 +00:00
|
|
|
}
|