From e2816bcb1e747b71752d0185282881da85fbf5fa Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Sat, 20 Sep 2025 21:21:30 -0400 Subject: [PATCH] directory watcher --- utils/DirectoryWatcher.qml | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 utils/DirectoryWatcher.qml diff --git a/utils/DirectoryWatcher.qml b/utils/DirectoryWatcher.qml new file mode 100644 index 0000000..776e4cf --- /dev/null +++ b/utils/DirectoryWatcher.qml @@ -0,0 +1,43 @@ +import QtQuick +import Quickshell.Io + +Item { + id: root + + required property string path + property bool recursive: true + property list fileFilter: [] + signal created(path: string) + signal modified(path: string) + signal deleted(path: string) + signal movedFrom(path: string) + signal movedTo(path: string) + + Process { + running: true + command: ["bash", "-c", `inotifywait -m ${root.recursive ? "-r" : ""} ${root.path} -e modify,move,create,delete --format "%e-%w%f"`] + stderr: StdioCollector { + onStreamFinished: console.error(`DirectoryWatcher: ${this.text}`) + } + stdout: SplitParser { + splitMarker: "\n" + onRead: data => { + const [action, path] = data.split("-"); + if (path.endsWith("~") || root.fileFilter.length > 0 && !root.fileFilter.some(filter => path.endsWith(filter))) { + return; + } + if (action.includes("CREATE")) { + root.created(path); + } else if (action.includes("MODIFY")) { + root.modified(path); + } else if (action.includes("DELETE")) { + root.deleted(path); + } else if (action.includes("MOVED_FROM")) { + root.movedFrom(path); + } else if (action.includes("MOVED_TO")) { + root.movedTo(path); + } + } + } + } +}