imap: auto-reconnects on connection error

if the worker emits a connection error, the ui will automatically send back a
reconnect command. The worker then establishes a new connection. Auto-reconnect
is disabled when the user sends the disconnect command.

Fixes: https://todo.sr.ht/~rjarry/aerc/1
Signed-off-by: Koni Marti <koni.marti@gmail.com>
This commit is contained in:
Koni Marti 2022-01-19 13:18:10 +01:00 committed by Robin Jarry
parent 1ace50a6b9
commit beae17a6da
3 changed files with 30 additions and 3 deletions
widgets

View file

@ -202,7 +202,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
switch msg.InResponseTo().(type) {
case *types.Connect:
case *types.Connect, *types.Reconnect:
acct.host.SetStatus("Listing mailboxes...")
acct.logger.Println("Listing mailboxes...")
acct.dirlist.UpdateList(func(dirs []string) {
@ -291,6 +291,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
case *types.ConnError:
acct.logger.Printf("Connection error = %v", msg.Error)
acct.aerc.PushError(fmt.Sprintf("%v", msg.Error))
acct.worker.PostAction(&types.Reconnect{}, nil)
case *types.Error:
acct.logger.Printf("%v", msg.Error)
acct.aerc.PushError(fmt.Sprintf("%v", msg.Error))