fixed slideshow interval

This commit is contained in:
Daniel Sommer 2023-11-16 17:07:38 +01:00
parent 20dd03dfe1
commit 718bddb4ad
2 changed files with 3 additions and 8 deletions

2
.vscode/launch.json vendored
View file

@ -8,7 +8,7 @@
"mode": "auto", "mode": "auto",
"program": "${workspaceFolder}/main.go", "program": "${workspaceFolder}/main.go",
"env":{ "env":{
"SLIDESHOW_INTERVAL": "10", "SLIDESHOW_INTERVAL": "13",
"SLIDESHOW_DIRECTORY": "/home/velvettear/images", "SLIDESHOW_DIRECTORY": "/home/velvettear/images",
"SLIDESHOW_RESOLUTION": "600x1024", "SLIDESHOW_RESOLUTION": "600x1024",
"SLIDESHOW_LOGLEVEL": "debug" "SLIDESHOW_LOGLEVEL": "debug"

View file

@ -15,16 +15,11 @@ import (
) )
// internal counter // internal counter
var counter int64
// start the slideshow // start the slideshow
func Start() { func Start() {
loggo.Info("starting the image slideshow...", "interval: "+strconv.FormatFloat(config.Interval.Seconds(), 'f', 0, 64)+" seconds") loggo.Info("starting the image slideshow...", "interval: "+strconv.FormatFloat(config.Interval.Seconds(), 'f', 0, 64)+" seconds")
var sleepTime time.Duration
for { for {
var sleepTime time.Duration
if counter > 0 {
sleepTime = time.Until(time.Now().Add(config.Interval))
}
var scaledImage string var scaledImage string
image := watcher.GetRandomImage() image := watcher.GetRandomImage()
if len(config.Resolution) > 0 { if len(config.Resolution) > 0 {
@ -38,11 +33,11 @@ func Start() {
if sleepTime > 0 { if sleepTime > 0 {
time.Sleep(sleepTime) time.Sleep(sleepTime)
} }
sleepTime = time.Until(time.Now().Add(config.Interval))
error := setBackground(image) error := setBackground(image)
if error != nil { if error != nil {
loggo.Error("encountered an error setting the background image", "image: "+image, error.Error()) loggo.Error("encountered an error setting the background image", "image: "+image, error.Error())
} }
counter++
loggo.Info("set new background image", "image: "+image) loggo.Info("set new background image", "image: "+image)
if len(scaledImage) > 0 { if len(scaledImage) > 0 {
error = os.Remove(scaledImage) error = os.Remove(scaledImage)