From 52902aa5c89c2ef920ea0868a7deb5f55a5816b8 Mon Sep 17 00:00:00 2001 From: andrzej Date: Sun, 3 Nov 2024 09:34:45 +0100 Subject: [PATCH] hacky solution to race condition --- slideshow.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/slideshow.go b/slideshow.go index 31968d8..b0e22af 100644 --- a/slideshow.go +++ b/slideshow.go @@ -1,7 +1,7 @@ package main import ( - "bufio" + // "bufio" "fmt" "log" "os/exec" @@ -14,14 +14,15 @@ func slideshow(ch <-chan string) { //set a flat background color based on config defaults 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() - } - }() + // stdout, _ := fillCmd.StdoutPipe() + // scanner := bufio.NewScanner(stdout) + // out := make(chan string) + // go func() { + // for scanner.Scan() { + // fmt.Println("scanner: ", scanner.Text()) + // out <- scanner.Text() + // } + // }() ready := make(chan bool) go func() { @@ -29,7 +30,8 @@ func slideshow(ch <-chan string) { if err != nil { fmt.Println("could not set background color", err) } - <-out + //NOTE: this is *very* hacky, but it is difficult to know when swaybg has initiated + time.Sleep(100 * time.Millisecond) ready <- true fmt.Println("bg color set!") fillCmd.Wait() @@ -38,6 +40,7 @@ func slideshow(ch <-chan string) { var cmd *exec.Cmd go func() { for { + <-ready newCmd := setRandomWallpaper(dir) if cmd != nil { err := cmd.Process.Kill()