wallpaper service

This commit is contained in:
Benjamin Palko 2025-09-20 23:08:57 -04:00
parent 9c074dc9e5
commit 3d1816c0f1

View file

@ -1,5 +1,7 @@
pragma Singleton
import qs.config
import qs.utils
import Quickshell
import Quickshell.Io
@ -7,18 +9,44 @@ Singleton {
id: root
property string directory: "~/Wallpapers/"
property list<url> files: []
property alias files: properties.files
property alias currentWallpaper: properties.currentWallpaper
property list<string> fileTypes: ["jpg", "jpeg", "png"]
property string command: `find ${root.directory} -maxdepth 1 -type f`
Process {
running: true
command: ["bash", "-c", `find "$dir" -maxdepth 1 -type f & inotifywait -m -r ${root.directory} -e modify,move,create,delete | while read dir action; do find "$dir" -maxdepth 1 -type f; done`]
stderr: StdioCollector {
onStreamFinished: console.log(`line read: ${this.text}`)
command: ["bash", "-c", `find ${root.directory} -maxdepth 1 -type f`]
stdout: StdioCollector {
onStreamFinished: {
root.files = this.text.split("\n");
}
}
stdout: SplitParser {
splitMarker: "\n"
onRead: data => root.files = data?.split("\n") ?? []
}
DirectoryWatcher {
path: root.directory
fileFilter: ["jpg", "jpeg", "png"]
onCreated: path => root.files.push(path)
onDeleted: path => root.files.filter(file => file != path)
onMovedFrom: path => root.files.filter(file => file != path)
onMovedTo: path => path => root.files.push(path)
}
FileView {
path: `${Paths.cache}/wallpaper.json`
watchChanges: true
onFileChanged: reload()
// when changes are made to properties in the adapter, save them
onAdapterUpdated: writeAdapter()
JsonAdapter {
id: properties
property url currentWallpaper: ""
property list<string> files: []
}
}
}