2021-11-01 20:38:26 +00:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2022-03-18 21:35:33 +00:00
|
|
|
"git.sr.ht/~rjarry/aerc/lib/statusline"
|
2021-11-01 20:38:26 +00: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 21:35:33 +00:00
|
|
|
cb := func(msg types.WorkerMessage) {
|
|
|
|
acct.SetStatus(statusline.ConnectionActivity(""))
|
|
|
|
}
|
2021-11-01 20:38:26 +00:00
|
|
|
if args[0] == "connect" {
|
2022-03-18 21:35:33 +00:00
|
|
|
acct.Worker().PostAction(&types.Connect{}, cb)
|
|
|
|
acct.SetStatus(statusline.ConnectionActivity("Connecting..."))
|
2021-11-01 20:38:26 +00:00
|
|
|
} else {
|
2022-03-18 21:35:33 +00:00
|
|
|
acct.Worker().PostAction(&types.Disconnect{}, cb)
|
|
|
|
acct.SetStatus(statusline.ConnectionActivity("Disconnecting..."))
|
2021-11-01 20:38:26 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|