background fill (introduces race condition!)
This commit is contained in:
parent
3d5d38de51
commit
91f87397b0
22
slideshow.go
22
slideshow.go
|
@ -9,19 +9,33 @@ import (
|
|||
|
||||
func slideshow(ch <-chan string) {
|
||||
dir := <-ch
|
||||
ticker := time.NewTicker(time.Duration(config.Duration) * time.Second)
|
||||
ticker := time.NewTicker(time.Duration(config.Duration) * time.Minute)
|
||||
|
||||
//set a flat background color based on config defaults
|
||||
// err = exec.Command("swaybg", "-i", img, "--mode", "fit").Run()
|
||||
fillReady := 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)
|
||||
}
|
||||
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()
|
||||
if err != nil {
|
||||
log.Fatal("could not kill process", err)
|
||||
}
|
||||
}
|
||||
cmd = setRandomWallpaper(dir)
|
||||
cmd = newCmd
|
||||
select {
|
||||
case dir = <-ch:
|
||||
log.Println("directory set!")
|
||||
|
@ -38,9 +52,9 @@ func setRandomWallpaper(dir string) *exec.Cmd {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("setting wallpaper: %v\n", img)
|
||||
|
||||
cmd := exec.Command("swaybg", "-i", img, "--mode", "fit")
|
||||
fmt.Printf("setting wallpaper: %v\n", img)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
log.Fatal("failed to set wallpaper!", err)
|
||||
|
|
Loading…
Reference in New Issue