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:
Sebastian Mark 2024-11-06 09:03:25 +01:00
parent 1dd42d3c14
commit 05e8bf5854
6 changed files with 54 additions and 39 deletions

View file

@ -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(),
)
}