attempted fix of race condition

This commit is contained in:
andrzej 2024-10-31 16:09:18 +01:00
parent 91f87397b0
commit b317ef0339
1 changed files with 14 additions and 4 deletions

View File

@ -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()