2021-11-01 21:38:26 +01:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2022-03-18 22:35:33 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/lib/statusline"
|
2021-11-01 21:38:26 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
|
|
|
"git.sr.ht/~rjarry/aerc/worker/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Connection struct{}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
register(Connection{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Connection) Aliases() []string {
|
|
|
|
return []string{"connect", "disconnect"}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Connection) Complete(aerc *widgets.Aerc, args []string) []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Connection) Execute(aerc *widgets.Aerc, args []string) error {
|
|
|
|
acct := aerc.SelectedAccount()
|
|
|
|
if acct == nil {
|
|
|
|
return errors.New("No account selected")
|
|
|
|
}
|
2022-03-18 22:35:33 +01:00
|
|
|
cb := func(msg types.WorkerMessage) {
|
|
|
|
acct.SetStatus(statusline.ConnectionActivity(""))
|
|
|
|
}
|
2021-11-01 21:38:26 +01:00
|
|
|
if args[0] == "connect" {
|
2022-03-18 22:35:33 +01:00
|
|
|
acct.Worker().PostAction(&types.Connect{}, cb)
|
|
|
|
acct.SetStatus(statusline.ConnectionActivity("Connecting..."))
|
2021-11-01 21:38:26 +01:00
|
|
|
} else {
|
2022-03-18 22:35:33 +01:00
|
|
|
acct.Worker().PostAction(&types.Disconnect{}, cb)
|
|
|
|
acct.SetStatus(statusline.ConnectionActivity("Disconnecting..."))
|
2021-11-01 21:38:26 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|