extensions fix
This commit is contained in:
parent
9faa121e1f
commit
999510731d
15
files.go
15
files.go
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
4
image.go
4
image.go
|
@ -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
27
main.go
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue