rudimentary slideshow functionality

This commit is contained in:
andrzej 2024-10-29 16:18:21 +01:00
parent ab5b679896
commit e859037fd5
5 changed files with 31 additions and 10 deletions

View File

@ -8,7 +8,8 @@ import (
type Config struct {
ImageFilters
Root string
Root string
Duration int
}
func (config *Config) load() {

View File

@ -3,5 +3,6 @@
"colorize":[ 247,40,60 ],
"contrast":-35,
"gamma":0.8,
"root":"/home/andrzej/bgs"
"root":"/home/andrzej/bgs",
"duration":1
}

15
main.go
View File

@ -15,12 +15,15 @@ func main() {
config.load()
fmt.Printf("%+v\n", config)
args := []string{""}
if len(os.Args) > 0 {
args = os.Args[1:]
var dir string
args := os.Args[1:]
if len(args) > 0 {
dir = args[0]
} else {
dir = ""
}
curr, err := pickRandomImage(args[0])
curr, err := pickRandomImage(dir)
if err != nil {
log.Fatal("failed to pick image!", err)
}
@ -29,6 +32,8 @@ func main() {
var waitGroup sync.WaitGroup
waitGroup.Add(1)
go server(&waitGroup)
go server()
go slideshow(dir)
waitGroup.Wait()
}

View File

@ -6,11 +6,10 @@ import (
"os"
"os/signal"
"strings"
"sync"
"syscall"
)
func server(waitGroup *sync.WaitGroup) {
func server() {
sockfile := "/tmp/bg-go.sock"
//Create a Unix domain socket and listen for incoming connections.

View File

@ -1,5 +1,20 @@
package main
func slideshow(dir string) {
import (
"log"
"time"
)
func slideshow(dir string) {
//TODO: use channel to allow changing dir mid flow
log.Println("starting slideshow goroutine")
for {
time.Sleep(time.Duration(config.Duration) * time.Minute)
img, err := pickRandomImage(dir)
if err != nil {
panic(err)
}
hyprpaperSet(img)
log.Println("hyprpaper set!")
}
}