send: enter no-quit mode until message is sent

Protect the sending of a message by entering the no-quit mode. This
prevents aerc from exiting with the :quit command until the operation is
done or the exit is forced.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-07-11 20:23:42 +02:00 committed by Robin Jarry
parent e200cd56bf
commit 76b39311dc
1 changed files with 7 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/google/shlex"
"github.com/pkg/errors"
"git.sr.ht/~rjarry/aerc/commands/mode"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
@ -96,6 +97,9 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
aerc.RemoveTab(composer)
aerc.PushStatus("Sending...", 10*time.Second)
// enter no-quit mode
mode.NoQuit()
var copyBuf bytes.Buffer // for the Sent folder content if CopyTo is set
failCh := make(chan error)
@ -136,6 +140,9 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
go func() {
defer logging.PanicHandler()
// leave no-quit mode
defer mode.NoQuitDone()
err = <-failCh
if err != nil {
aerc.PushError(strings.ReplaceAll(err.Error(), "\n", " "))