From aa9916ad9a7b6e2319ab10c5581bbdb6a1f52e0b Mon Sep 17 00:00:00 2001 From: velvettear Date: Fri, 17 Nov 2023 13:27:52 +0100 Subject: [PATCH] scale images after setting a new wallpaper for improved performance --- internal/slideshow/slideshow.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/slideshow/slideshow.go b/internal/slideshow/slideshow.go index 976e98d..3663466 100644 --- a/internal/slideshow/slideshow.go +++ b/internal/slideshow/slideshow.go @@ -18,15 +18,23 @@ import ( func Start() { loggo.Info("starting the image slideshow...", "interval: "+strconv.FormatFloat(config.Interval.Seconds(), 'f', 0, 64)+" seconds") var sleepTime time.Duration + scaleImages := config.IsResolutionSet() for { + var data []byte image := watcher.GetRandomImage() - if config.IsResolutionSet() { - data, error := scale(image) + if scaleImages { + tmp, error := scale(image) if error != nil { loggo.Error("encountered an error scaling an image", "image: "+image, error.Error()) continue } - error = setBackgroundPiped(data) + data = tmp + } + if sleepTime > 0 { + time.Sleep(sleepTime) + } + if scaleImages { + error := setBackgroundPiped(data) if error != nil { loggo.Error("encountered an error setting the background via pipe to feh's stdin", error.Error()) } @@ -38,9 +46,6 @@ func Start() { } loggo.Info("set new background image", "image: "+image) } - if sleepTime > 0 { - time.Sleep(sleepTime) - } sleepTime = time.Until(time.Now().Add(config.Interval)) } }