about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--widgets/account-wizard.go7
-rw-r--r--widgets/account.go13
-rw-r--r--widgets/aerc.go27
3 files changed, 39 insertions, 8 deletions
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index 59f22e7..f47e97e 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -534,8 +534,13 @@ func (wizard *AccountWizard) finish(tutorial bool) {
 	}
 	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)
+	if err != nil {
+		wizard.aerc.NewTab(errorScreen(err.Error(), wizard.conf.Ui),
+			account.Name)
+		return
+	}
 	wizard.aerc.accounts[account.Name] = view
 	wizard.aerc.NewTab(view, account.Name)
 
diff --git a/widgets/account.go b/widgets/account.go
index 53c65ba..bb29ce0 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -32,14 +32,18 @@ type AccountView struct {
 }
 
 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{
 		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,
-	logger *log.Logger, host TabHost) *AccountView {
+	logger *log.Logger, host TabHost) (*AccountView, error) {
 
 	acctUiConf := conf.GetUiConfig(map[config.ContextType]string{
 		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)
 	if err != nil {
 		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
 
@@ -83,7 +88,7 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
 	worker.PostAction(&types.Connect{}, view.connected)
 	host.SetStatus("Connecting...")
 
-	return view
+	return view, nil
 }
 
 func (acct *AccountView) Tick() bool {
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 692e00d..acdd8b4 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -84,9 +84,13 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
 	conf.Triggers.ExecuteCommand = cmd
 
 	for i, acct := range conf.Accounts {
-		view := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc)
-		aerc.accounts[acct.Name] = view
-		tabs.Add(view, acct.Name)
+		view, err := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc)
+		if err != nil {
+			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 {
@@ -609,3 +613,20 @@ func (aerc *Aerc) DecryptKeys(keys []openpgp.Key, symmetric bool) (b []byte, 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
+}