aboutsummaryrefslogtreecommitdiffstats
path: root/config/accounts.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-12 15:03:30 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-14 11:22:58 +0100
commitc05c2ffe0424b048b10e7dd1aca59ae9cf631f12 (patch)
tree13a3a84eb74fdea77996161f01bec5596f67f39f /config/accounts.go
parent9d0297e9d913a92b2d7ae02692e83f0f4093a766 (diff)
downloadaerc-c05c2ffe0424b048b10e7dd1aca59ae9cf631f12.tar.gz
config: make various sections accessible via global vars
There is only one instance of AercConfig which is associated to the Aerc widget. Everywhere we need to access configuration options, we need somehow to get a reference either to the Aerc widget or to a pointer to the AercConfig instance. This makes the code cluttered. Remove the AercConfig structure and every place where it is referenced. Instead, declare global variables for every configuration section and access them directly from the `config` module. Since bindings and ui sections can be "contextual" (i.e. per account, per folder or per subject), leave most local references intact. Replacing them with config.{Ui,Binds}.For{Account,Folder,Subject} would make this patch even more unreadable. This is something that may be addressed in the future. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'config/accounts.go')
-rw-r--r--config/accounts.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/config/accounts.go b/config/accounts.go
index 61f0e282..54c6556f 100644
--- a/config/accounts.go
+++ b/config/accounts.go
@@ -104,9 +104,11 @@ type AccountConfig struct {
TrustedAuthRes []string `ini:"trusted-authres" delim:","`
}
-func (config *AercConfig) parseAccounts(root string, accts []string) error {
+var Accounts []*AccountConfig
+
+func parseAccounts(root string, accts []string) error {
filename := path.Join(root, "accounts.conf")
- if !config.General.UnsafeAccountsConf {
+ if !General.UnsafeAccountsConf {
if err := checkConfigPerms(filename); err != nil {
return err
}
@@ -217,15 +219,15 @@ func (config *AercConfig) parseAccounts(root string, accts []string) error {
}
log.Debugf("accounts.conf: [%s] from = %s", account.Name, account.From)
- config.Accounts = append(config.Accounts, account)
+ Accounts = append(Accounts, &account)
}
if len(accts) > 0 {
// Sort accounts struct to match the specified order, if we
// have one
- if len(config.Accounts) != len(accts) {
+ if len(Accounts) != len(accts) {
return errors.New("account(s) not found")
}
- sort.Slice(config.Accounts, func(i, j int) bool {
+ sort.Slice(Accounts, func(i, j int) bool {
return strings.ToLower(accts[i]) < strings.ToLower(accts[j])
})
}