From e859037fd5fa6e4103af1c95bed3eb863c853734 Mon Sep 17 00:00:00 2001 From: andrzej Date: Tue, 29 Oct 2024 16:18:21 +0100 Subject: [PATCH] rudimentary slideshow functionality --- config.go | 3 ++- config.json | 3 ++- main.go | 15 ++++++++++----- server.go | 3 +-- slideshow.go | 17 ++++++++++++++++- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 168e136..f57ce23 100644 --- a/config.go +++ b/config.go @@ -8,7 +8,8 @@ import ( type Config struct { ImageFilters - Root string + Root string + Duration int } func (config *Config) load() { diff --git a/config.json b/config.json index 35f3eaa..3feee89 100644 --- a/config.json +++ b/config.json @@ -3,5 +3,6 @@ "colorize":[ 247,40,60 ], "contrast":-35, "gamma":0.8, -"root":"/home/andrzej/bgs" +"root":"/home/andrzej/bgs", +"duration":1 } diff --git a/main.go b/main.go index 982646f..a8b47c3 100644 --- a/main.go +++ b/main.go @@ -15,12 +15,15 @@ func main() { config.load() fmt.Printf("%+v\n", config) - args := []string{""} - if len(os.Args) > 0 { - args = os.Args[1:] + var dir string + args := os.Args[1:] + if len(args) > 0 { + dir = args[0] + } else { + dir = "" } - curr, err := pickRandomImage(args[0]) + curr, err := pickRandomImage(dir) if err != nil { log.Fatal("failed to pick image!", err) } @@ -29,6 +32,8 @@ func main() { var waitGroup sync.WaitGroup waitGroup.Add(1) - go server(&waitGroup) + go server() + + go slideshow(dir) waitGroup.Wait() } diff --git a/server.go b/server.go index 290b60c..2ae34ea 100644 --- a/server.go +++ b/server.go @@ -6,11 +6,10 @@ import ( "os" "os/signal" "strings" - "sync" "syscall" ) -func server(waitGroup *sync.WaitGroup) { +func server() { sockfile := "/tmp/bg-go.sock" //Create a Unix domain socket and listen for incoming connections. diff --git a/slideshow.go b/slideshow.go index bce00f4..fb4f246 100644 --- a/slideshow.go +++ b/slideshow.go @@ -1,5 +1,20 @@ package main -func slideshow(dir string) { +import ( + "log" + "time" +) +func slideshow(dir string) { + //TODO: use channel to allow changing dir mid flow + log.Println("starting slideshow goroutine") + for { + time.Sleep(time.Duration(config.Duration) * time.Minute) + img, err := pickRandomImage(dir) + if err != nil { + panic(err) + } + hyprpaperSet(img) + log.Println("hyprpaper set!") + } }