feat: reconnect on disconnect (add status to TUI)
- add `Connected()` method for client - add `LastErr` field to GoTomatoClient - replace error logging by updating `LastErr` field - modify methods to use pointer receivers for Client - add `prevMessage` variable to store the last received server message - show connect status in TUI - use EnterAltScreen instead of ClearScreen
This commit is contained in:
parent
1dd42d3c14
commit
05e8bf5854
6 changed files with 54 additions and 39 deletions
|
@ -49,10 +49,14 @@ func (a app) waitForChannelSignal() tea.Cmd {
|
|||
func (a app) Init() tea.Cmd {
|
||||
client = websocket.Connect(config.URL)
|
||||
client.Password = config.Password
|
||||
if client.LastErr != nil {
|
||||
helper.Logger.Fatal(client.LastErr)
|
||||
}
|
||||
|
||||
go client.ProcessServerMessages(a.channel)
|
||||
|
||||
return tea.Batch(
|
||||
tea.ClearScreen,
|
||||
tea.EnterAltScreen,
|
||||
a.waitForChannelSignal(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -3,22 +3,29 @@ package client
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/colour"
|
||||
|
||||
"git.smsvc.net/pomodoro/ChronoTomato/cmd/client/helper"
|
||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
func (a app) View() string {
|
||||
var body string
|
||||
var serverStatus string
|
||||
|
||||
body = "Waiting for server message..."
|
||||
if a.pomodoro != (GoTomato.ServerMessage{}) {
|
||||
body = helper.TerminalOutput(a.pomodoro)
|
||||
helper.DesktopNotifications(a.pomodoro)
|
||||
} else {
|
||||
body = "Waiting for first server message..."
|
||||
}
|
||||
|
||||
serverStatus = colour.Sprintf("^D^1disconnected: %v^R\n", client.LastErr)
|
||||
if client.Connected() {
|
||||
serverStatus = colour.Sprintf("^D^2connected to %s^R\n", client.Server)
|
||||
}
|
||||
|
||||
helpView := a.help.View(a.keys)
|
||||
height := 8 - strings.Count(body, "\n") - strings.Count(helpView, "\n")
|
||||
height := 8 - strings.Count(body, "\n") - strings.Count(serverStatus, "\n") - strings.Count(helpView, "\n")
|
||||
|
||||
return body + strings.Repeat("\n", height) + helpView
|
||||
return body + strings.Repeat("\n", height) + serverStatus + helpView
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue