Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
return func() tea.Msg {
for i := 0; ; i++ {
if err := conn.Connect(); err == nil {
conn.RequestStatus()

Check failure on line 77 in internal/tui/model.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `conn.RequestStatus` is not checked (errcheck)
return connStatusMsg(ConnConnected)
}
if i >= 30 {
Expand All @@ -89,22 +89,7 @@
return func() tea.Msg {
for {
if err := conn.Connect(); err == nil {
_ = conn.RequestStatus()
return connStatusMsg(ConnConnected)
}
if i >= 30 {
return connStatusMsg(ConnFailed)
}
time.Sleep(time.Second)
}
}
}

func reconnectCmd(conn *client.Conn) tea.Cmd {
return func() tea.Msg {
for {
if err := conn.Connect(); err == nil {
_ = conn.RequestStatus()
conn.RequestStatus()

Check failure on line 92 in internal/tui/model.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `conn.RequestStatus` is not checked (errcheck)
return connStatusMsg(ConnConnected)
}
time.Sleep(time.Second)
Expand Down Expand Up @@ -144,7 +129,7 @@
case reconnectMsg:
if m.connStatus == ConnFailed || m.connStatus == ConnDisconnected {
if err := m.conn.Connect(); err == nil {
m.conn.RequestStatus()

Check failure on line 132 in internal/tui/model.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `m.conn.RequestStatus` is not checked (errcheck)
m.connStatus = ConnConnected
return m, listenCmd(m.conn)
}
Expand Down Expand Up @@ -176,24 +161,30 @@

func listenCmd(conn *client.Conn) tea.Cmd {
return func() tea.Msg {
for {

Check failure on line 164 in internal/tui/model.go

View workflow job for this annotation

GitHub Actions / build

S1000: should use for range instead of for { select {} } (staticcheck)
select {
case env, ok := <-conn.Messages:
if !ok {
return reconnectMsg{}
}
if err := json.Unmarshal(env.Payload, &payload); err == nil {
return outputMsg(payload.Content)
switch env.Type {
case "output_deliver":
var payload struct {
Content string `json:"content"`
ContentType string `json:"content_type"`
}
if err := json.Unmarshal(env.Payload, &payload); err == nil {
return outputMsg(payload.Content)
}
case "status_response":
return statusMsg("connected")
case "input_accepted":
return statusMsg("sent")
case "audit_report":
return statusMsg("audit received")
}
case "status_response":
return statusMsg("connected")
case "input_accepted":
return statusMsg("sent")
case "audit_report":
return statusMsg("audit received")
}
}
return reconnectMsg{}
}
}

Expand Down
Loading