extensions fix

This commit is contained in:
andrzej 2024-10-27 18:15:14 +01:00
parent 9faa121e1f
commit 999510731d
4 changed files with 36 additions and 18 deletions

View File

@ -1,7 +1,7 @@
package main
import (
// "fmt"
"fmt"
"math/rand"
"os"
"regexp"
@ -33,3 +33,16 @@ func getRandomFile(dir string) (path string, filename string, error error) {
}
return dir + "/" + randomImg.Name(), randomImg.Name(), nil
}
func fileExists(filename string) (bool, error) {
files, err := os.ReadDir("images")
if err != nil {
return false, err
}
for _, file := range files {
if file.Name() == filename {
return true, nil
}
}
return false, nil
}

View File

@ -2,10 +2,12 @@ package main
import (
"errors"
"log"
"os/exec"
)
func hyprpaperPreload(path string) error {
log.Println("path: ", path)
out, err := exec.Command("hyprctl", "hyprpaper", "preload", path).Output()
if err != nil {
return err
@ -22,7 +24,7 @@ func hyprpaperWallpaper(path string) error {
}
func hyprpaperUnloadAll() error {
out, err := exec.Command("hyprctl", "hyprpaper", "unload", "all").Output()
out, err := exec.Command("hyprctl", "hyprpaper", "unload", "unused").Output()
if err != nil {
return err
}

View File

@ -1,11 +1,12 @@
package main
import (
"github.com/disintegration/gift"
"image"
"log"
"os"
"github.com/disintegration/gift"
_ "image/jpeg"
"image/png"
)
@ -31,6 +32,7 @@ func loadImage(filename string) image.Image {
}
func saveImage(filename string, img image.Image) {
log.Println("new filename: ", filename)
f, err := os.Create(filename)
if err != nil {
log.Fatalf("os.Create failed: %v", err)

27
main.go
View File

@ -4,6 +4,8 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
)
func main() {
@ -19,25 +21,24 @@ func main() {
log.Fatal("couldn't find working directory", err)
}
// // apply curr.png if already preloaded
// err = hyprpaperWallpaper(curr)
// if err != nil {
// //preload curr.png if not
// err = hyprpaperPreload(curr)
// if err != nil {
// fmt.Println("could not preload (this is fine)", err)
// }
// }
dir := config.Root + "/chsck"
randomImg, filename, _ := getRandomFile(dir)
filenameNoExt := strings.TrimSuffix(filename, filepath.Ext(filename))
//check to see if rendered copy already exists
fileExists, err := fileExists(filenameNoExt)
if err != nil {
log.Fatal("failure checking if file exists!", err)
}
curr := wd + "/images/" + filenameNoExt
log.Println("curr: ", curr)
if !fileExists {
img := loadImage(randomImg)
dst := processImage(img, config)
curr := wd + "/images/" + filename
log.Println("curr: ", curr)
saveImage(curr, dst)
} else {
log.Println("file exists! skipping image processing")
}
//BUG: hyprpaper won't preload if it recognises the path. SO we need to use images' original names
err = hyprpaperPreload(curr)
if err != nil {
log.Fatal("preload failed!", err)