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
🤖
This commit is contained in:
parent
b943c9d6eb
commit
0ca90b50a5
6 changed files with 25 additions and 18 deletions
|
@ -4,11 +4,9 @@ import (
|
|||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
"time"
|
||||
|
||||
"git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
||||
)
|
||||
|
||||
func Connect(url string) models.Client {
|
||||
func Connect(url string) Client {
|
||||
log.Info("Connected ", "host", url)
|
||||
|
||||
conn, _, err := websocket.DefaultDialer.Dial(url, nil)
|
||||
|
@ -16,10 +14,10 @@ func Connect(url string) models.Client {
|
|||
log.Fatal("Dial error!", "reason", err)
|
||||
}
|
||||
|
||||
return models.Client{Conn: conn}
|
||||
return Client{Conn: conn}
|
||||
}
|
||||
|
||||
func Disconnect(client models.Client) {
|
||||
func Disconnect(client Client) {
|
||||
select {
|
||||
case <-Done:
|
||||
// session closed by remote
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue