show error if account view creation fails
This can happen for example if aerc is compiled without notmuch support but the notmuch worker is requested. Pushing a status message isn't good enough, as this gets overridden pretty quickly if one has multiple accounts configured. So we show a fullscreen error instead.
This commit is contained in:
parent
c3c982c3ec
commit
2d7a870725
3 changed files with 39 additions and 8 deletions
|
@ -534,8 +534,13 @@ func (wizard *AccountWizard) finish(tutorial bool) {
|
||||||
}
|
}
|
||||||
wizard.conf.Accounts = append(wizard.conf.Accounts, account)
|
wizard.conf.Accounts = append(wizard.conf.Accounts, account)
|
||||||
|
|
||||||
view := NewAccountView(wizard.aerc, wizard.conf, &account,
|
view, err := NewAccountView(wizard.aerc, wizard.conf, &account,
|
||||||
wizard.aerc.logger, wizard.aerc)
|
wizard.aerc.logger, wizard.aerc)
|
||||||
|
if err != nil {
|
||||||
|
wizard.aerc.NewTab(errorScreen(err.Error(), wizard.conf.Ui),
|
||||||
|
account.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
wizard.aerc.accounts[account.Name] = view
|
wizard.aerc.accounts[account.Name] = view
|
||||||
wizard.aerc.NewTab(view, account.Name)
|
wizard.aerc.NewTab(view, account.Name)
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,18 @@ type AccountView struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (acct *AccountView) UiConfig() config.UIConfig {
|
func (acct *AccountView) UiConfig() config.UIConfig {
|
||||||
|
var folder string
|
||||||
|
if dirlist := acct.Directories(); dirlist != nil {
|
||||||
|
folder = dirlist.Selected()
|
||||||
|
}
|
||||||
return acct.conf.GetUiConfig(map[config.ContextType]string{
|
return acct.conf.GetUiConfig(map[config.ContextType]string{
|
||||||
config.UI_CONTEXT_ACCOUNT: acct.AccountConfig().Name,
|
config.UI_CONTEXT_ACCOUNT: acct.AccountConfig().Name,
|
||||||
config.UI_CONTEXT_FOLDER: acct.Directories().Selected(),
|
config.UI_CONTEXT_FOLDER: folder,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountConfig,
|
func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountConfig,
|
||||||
logger *log.Logger, host TabHost) *AccountView {
|
logger *log.Logger, host TabHost) (*AccountView, error) {
|
||||||
|
|
||||||
acctUiConf := conf.GetUiConfig(map[config.ContextType]string{
|
acctUiConf := conf.GetUiConfig(map[config.ContextType]string{
|
||||||
config.UI_CONTEXT_ACCOUNT: acct.Name,
|
config.UI_CONTEXT_ACCOUNT: acct.Name,
|
||||||
|
@ -65,7 +69,8 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
|
||||||
worker, err := worker.NewWorker(acct.Source, logger)
|
worker, err := worker.NewWorker(acct.Source, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
host.SetError(fmt.Sprintf("%s: %s", acct.Name, err))
|
host.SetError(fmt.Sprintf("%s: %s", acct.Name, err))
|
||||||
return view
|
logger.Printf("%s: %s\n", acct.Name, err)
|
||||||
|
return view, err
|
||||||
}
|
}
|
||||||
view.worker = worker
|
view.worker = worker
|
||||||
|
|
||||||
|
@ -83,7 +88,7 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
|
||||||
worker.PostAction(&types.Connect{}, view.connected)
|
worker.PostAction(&types.Connect{}, view.connected)
|
||||||
host.SetStatus("Connecting...")
|
host.SetStatus("Connecting...")
|
||||||
|
|
||||||
return view
|
return view, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (acct *AccountView) Tick() bool {
|
func (acct *AccountView) Tick() bool {
|
||||||
|
|
|
@ -84,9 +84,13 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
|
||||||
conf.Triggers.ExecuteCommand = cmd
|
conf.Triggers.ExecuteCommand = cmd
|
||||||
|
|
||||||
for i, acct := range conf.Accounts {
|
for i, acct := range conf.Accounts {
|
||||||
view := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc)
|
view, err := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc)
|
||||||
aerc.accounts[acct.Name] = view
|
if err != nil {
|
||||||
tabs.Add(view, acct.Name)
|
tabs.Add(errorScreen(err.Error(), conf.Ui), acct.Name)
|
||||||
|
} else {
|
||||||
|
aerc.accounts[acct.Name] = view
|
||||||
|
tabs.Add(view, acct.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(conf.Accounts) == 0 {
|
if len(conf.Accounts) == 0 {
|
||||||
|
@ -609,3 +613,20 @@ func (aerc *Aerc) DecryptKeys(keys []openpgp.Key, symmetric bool) (b []byte, err
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// errorScreen is a widget that draws an error in the middle of the context
|
||||||
|
func errorScreen(s string, conf config.UIConfig) ui.Drawable {
|
||||||
|
errstyle := conf.GetStyle(config.STYLE_ERROR)
|
||||||
|
text := ui.NewText(s, errstyle).Strategy(ui.TEXT_CENTER)
|
||||||
|
grid := ui.NewGrid().Rows([]ui.GridSpec{
|
||||||
|
{ui.SIZE_WEIGHT, ui.Const(1)},
|
||||||
|
{ui.SIZE_EXACT, ui.Const(1)},
|
||||||
|
{ui.SIZE_WEIGHT, ui.Const(1)},
|
||||||
|
}).Columns([]ui.GridSpec{
|
||||||
|
{ui.SIZE_WEIGHT, ui.Const(1)},
|
||||||
|
})
|
||||||
|
grid.AddChild(ui.NewFill(' ')).At(0, 0)
|
||||||
|
grid.AddChild(text).At(1, 0)
|
||||||
|
grid.AddChild(ui.NewFill(' ')).At(2, 0)
|
||||||
|
return grid
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue