config: fix setting of zero-value time.Duration config values
When using section.MapTo(struct) (go-ini), if the struct has a default value for a time.Duration type, a zero-value in the config will not overwrite the default. If the type is *time.Duration, it will be overwritten properly. One consideration was to change all time.Duration types to *time.Duration. This method was chosen for ease of implementation. For example, if you set dirlist-delay = 0s, the delay will be 200ms. This can be observed by logging the value just after mapping the ui section in config.go. A config value of 0.1ms will have a delay of 0.1ms. Currently, aerc has 4 time.Duration config values: 1. DirlistDelay - default 200 ms 2. CompletionDelay - default 250 ms 3. CheckMail - default unset (0) 4. CheckMailTimeout - default 10 s 1, 2, and 4 have a non-zero default value and are subject to this bug. Only 1 and 2 are fixed in this patch. Number 4 would not make sense to have a 0 second timeout, therefore we can prevent the user from doing this by keeping it as it is. Another option could be to set these to 0 in config.go. The default config (aerc.conf) has these keys in it with their default values. Presumably, we don't need to set them again in config.go. If a user deletes the config values out of aerc.conf, the UI will function but with 0s delays. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
parent
be2abb3d91
commit
de24d2d590
1 changed files with 19 additions and 0 deletions
|
@ -467,6 +467,25 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
|
||||||
if err := validateBorderChars(ui, &config.Ui); err != nil {
|
if err := validateBorderChars(ui, &config.Ui); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Values with type=time.Duration must be explicitly set. If these
|
||||||
|
// values are given a default in the struct passed to ui.MapTo, which
|
||||||
|
// they are, a zero-value in the config won't overwrite the default.
|
||||||
|
for key, val := range ui.KeysHash() {
|
||||||
|
switch key {
|
||||||
|
case "dirlist-delay":
|
||||||
|
dur, err := time.ParseDuration(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
config.Ui.DirListDelay = dur
|
||||||
|
case "completion-delay":
|
||||||
|
dur, err := time.ParseDuration(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
config.Ui.CompletionDelay = dur
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sectionName := range file.SectionStrings() {
|
for _, sectionName := range file.SectionStrings() {
|
||||||
|
|
Loading…
Reference in a new issue