attempted fix of race condition
This commit is contained in:
parent
91f87397b0
commit
b317ef0339
18
slideshow.go
18
slideshow.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -12,22 +13,31 @@ func slideshow(ch <-chan string) {
|
||||||
ticker := time.NewTicker(time.Duration(config.Duration) * time.Minute)
|
ticker := time.NewTicker(time.Duration(config.Duration) * time.Minute)
|
||||||
|
|
||||||
//set a flat background color based on config defaults
|
//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() {
|
go func() {
|
||||||
fillCmd := exec.Command("swaybg", "-c", "#232136")
|
|
||||||
err := fillCmd.Start()
|
err := fillCmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("could not set background color", err)
|
fmt.Println("could not set background color", err)
|
||||||
}
|
}
|
||||||
|
<-out
|
||||||
|
ready <- true
|
||||||
fmt.Println("bg color set!")
|
fmt.Println("bg color set!")
|
||||||
fillReady <- true
|
|
||||||
fillCmd.Wait()
|
fillCmd.Wait()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
<-fillReady
|
|
||||||
newCmd := setRandomWallpaper(dir)
|
newCmd := setRandomWallpaper(dir)
|
||||||
if cmd != nil {
|
if cmd != nil {
|
||||||
err := cmd.Process.Kill()
|
err := cmd.Process.Kill()
|
||||||
|
|
Loading…
Reference in New Issue