diff --git a/slideshow.go b/slideshow.go index 76223ad..31968d8 100644 --- a/slideshow.go +++ b/slideshow.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "fmt" "log" "os/exec" @@ -12,22 +13,31 @@ func slideshow(ch <-chan string) { ticker := time.NewTicker(time.Duration(config.Duration) * time.Minute) //set a flat background color based on config defaults - fillReady := make(chan bool) + fillCmd := exec.Command("swaybg", "-c", "#232136") + stdout, _ := fillCmd.StdoutPipe() + scanner := bufio.NewScanner(stdout) + out := make(chan string) + go func() { + for scanner.Scan() { + out <- scanner.Text() + } + }() + + ready := make(chan bool) go func() { - fillCmd := exec.Command("swaybg", "-c", "#232136") err := fillCmd.Start() if err != nil { fmt.Println("could not set background color", err) } + <-out + ready <- true fmt.Println("bg color set!") - fillReady <- true fillCmd.Wait() }() var cmd *exec.Cmd go func() { for { - <-fillReady newCmd := setRandomWallpaper(dir) if cmd != nil { err := cmd.Process.Kill()