diff --git a/components/composite/WallpaperList.qml b/components/composite/WallpaperList.qml index 3dfb330..2a67f31 100644 --- a/components/composite/WallpaperList.qml +++ b/components/composite/WallpaperList.qml @@ -19,7 +19,7 @@ ListView { implicitHeight: 90 model: FolderListModel { nameFilters: ["*.jpg"] - folder: `file://${Paths.expandTilde(Config.wallpaper.directory)}` + folder: `${Paths.home}/Wallpapers` showDirs: false } delegate: Item { diff --git a/config/Config.qml b/config/Config.qml index 416d739..036f14c 100644 --- a/config/Config.qml +++ b/config/Config.qml @@ -7,7 +7,6 @@ Singleton { id: root readonly property alias powermenu: adapter.powermenu - readonly property alias wallpaper: adapter.wallpaper FileView { path: `${Paths.config}/shell.json` @@ -20,7 +19,6 @@ Singleton { id: adapter property var powermenu: PowerMenu {} - property var wallpaper: Wallpaper {} } } @@ -32,8 +30,4 @@ Singleton { property string text property string command } - - component Wallpaper: JsonObject { - property string directory - } } diff --git a/services/WallpaperService.qml b/services/WallpaperService.qml index 94adbbd..ea6bd0e 100644 --- a/services/WallpaperService.qml +++ b/services/WallpaperService.qml @@ -1,13 +1,37 @@ pragma Singleton import qs.config +import qs.utils import Quickshell import Quickshell.Io Singleton { id: root + property string directory: "~/Wallpapers/" + property alias files: properties.files property alias currentWallpaper: properties.currentWallpaper + property list fileTypes: ["jpg", "jpeg", "png"] + property string command: `find ${root.directory} -maxdepth 1 -type f` + + Process { + running: true + command: ["bash", "-c", `find ${root.directory} -maxdepth 1 -type f`] + stdout: StdioCollector { + onStreamFinished: { + root.files = this.text.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` @@ -22,6 +46,7 @@ Singleton { id: properties property url currentWallpaper: "" + property list files: [] } } }