feat: add keyboard controls
- add keyboard listener for space, r, and q keys
- create shared state for server messages
- update desktop and terminal notifications to use shared state
🤖
This commit is contained in:
parent
11c599a371
commit
4dcc984784
7 changed files with 107 additions and 9 deletions
|
@ -5,7 +5,10 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
|
||||
"ChronoTomato/internal/shared"
|
||||
"ChronoTomato/internal/websocket"
|
||||
"atomicgo.dev/keyboard"
|
||||
"atomicgo.dev/keyboard/keys"
|
||||
)
|
||||
|
||||
var interrupt = make(chan os.Signal, 1)
|
||||
|
@ -27,5 +30,30 @@ func Start() {
|
|||
|
||||
go websocket.ProcessServerMessages(conn)
|
||||
|
||||
keyboard.Listen(func(key keys.Key) (stop bool, err error) {
|
||||
switch key.String() {
|
||||
case "space":
|
||||
if !shared.ServerMessage.Ongoing {
|
||||
websocket.SendCmd(conn, "start", *password)
|
||||
return false, nil
|
||||
}
|
||||
if shared.ServerMessage.Paused {
|
||||
websocket.SendCmd(conn, "resume", *password)
|
||||
return false, nil
|
||||
} else {
|
||||
websocket.SendCmd(conn, "pause", *password)
|
||||
return false, nil
|
||||
}
|
||||
case "r":
|
||||
websocket.SendCmd(conn, "stop", *password)
|
||||
return false, nil
|
||||
case "q":
|
||||
interrupt <- os.Interrupt
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
})
|
||||
|
||||
websocket.WaitForDisconnect(conn, interrupt)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue