From a424a0dca14e189fdc3cc479f4ad367125568481 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Thu, 8 Oct 2020 23:33:34 -0400 Subject: [PATCH] Fix autosave not running by default --- cmd/micro/micro.go | 5 +++++ internal/config/autosave.go | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 502fb137..0a2a55aa 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -354,6 +354,11 @@ func main() { action.InfoBar.Error(clipErr, " or change 'clipboard' option") } + if a := config.GetGlobalOption("autosave").(float64); a > 0 { + config.SetAutoTime(int(a)) + config.StartAutoSave() + } + screen.Events = make(chan tcell.Event) // Here is the event loop which runs in a separate thread diff --git a/internal/config/autosave.go b/internal/config/autosave.go index db473081..2d0f8cec 100644 --- a/internal/config/autosave.go +++ b/internal/config/autosave.go @@ -31,14 +31,13 @@ func GetAutoTime() int { func StartAutoSave() { go func() { for { - if autotime < 1 { - break - } - time.Sleep(time.Duration(autotime) * time.Second) - // it's possible autotime was changed while sleeping - if autotime < 1 { + autolock.Lock() + a := autotime + autolock.Unlock() + if a < 1 { break } + time.Sleep(time.Duration(a) * time.Second) Autosave <- true } }()