From 8967e3a1f593ee289c00a6b245721c869e1e683a Mon Sep 17 00:00:00 2001 From: inorishio Date: Wed, 3 Dec 2025 13:53:58 +0100 Subject: [PATCH] Claude pog? --- .claude/settings.local.json | 12 ++++ .gitignore | 1 + Modules/ConfigLoader.qml | 131 ++++++++++++++++++++++++++++++++++++ Modules/GetGifs.qml | 24 ++++++- Modules/GifsLoader.qml | 3 +- Scripts/files.sh | 3 - shell.qml | 13 +++- 7 files changed, 179 insertions(+), 8 deletions(-) create mode 100644 .claude/settings.local.json create mode 100644 .gitignore create mode 100644 Modules/ConfigLoader.qml delete mode 100755 Scripts/files.sh diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..6ab560e --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,12 @@ +{ + "permissions": { + "allow": [ + "Bash(dir:*)", + "Bash(cat:*)", + "Bash(git ls-tree:*)", + "Bash(cd:*)" + ], + "deny": [], + "ask": [] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c5f206 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.claude/ diff --git a/Modules/ConfigLoader.qml b/Modules/ConfigLoader.qml new file mode 100644 index 0000000..c6fb42f --- /dev/null +++ b/Modules/ConfigLoader.qml @@ -0,0 +1,131 @@ +import QtCore +import QtQuick +import Quickshell.Io + +QtObject { + id: configLoader + property string gifFolder: "" + property bool loaded: false + property string configDir: StandardPaths.homeLocation + "/.config/QTPet" + property string configPath: configDir + "/config.json" + + signal folderChanged() + + // Process to check/create directory + property var dirCheckProcess: Process { + id: dirCheck + running: false + command: ["test", "-d", configLoader.configDir] + + onExited: { + if (exitCode !== 0) { + // Directory doesn't exist, create it + dirCreateProcess.running = true + } else { + // Directory exists, check for config file + fileCheckProcess.running = true + } + } + } + + // Process to create directory + property var dirCreateProcess: Process { + id: dirCreate + running: false + command: ["mkdir", "-p", configLoader.configDir] + + onExited: { + console.log("Created config directory:", configLoader.configDir) + // After creating directory, create default config + fileCreateProcess.running = true + } + } + + // Process to check if config file exists + property var fileCheckProcess: Process { + id: fileCheck + running: false + command: ["test", "-f", configLoader.configPath] + + onExited: { + if (exitCode !== 0) { + // File doesn't exist, create default config + fileCreateProcess.running = true + } else { + // File exists, load it + loadConfig() + } + } + } + + // Process to create default config file + property var fileCreateProcess: Process { + id: fileCreate + running: false + command: ["sh", "-c", "echo '{\"gifFolder\": \"$HOME/.config/quickshell/QtDesktopPet/Gifs\"}' > " + configLoader.configPath] + + onExited: { + console.log("Created default config file:", configLoader.configPath) + loadConfig() + } + } + + // Timer to watch for config file changes + property var configWatcher: Timer { + id: watcher + interval: 2000 // Check every 2 seconds + running: configLoader.loaded + repeat: true + + property string lastContent: "" + + onTriggered: { + try { + let currentContent = Qt.readFile(configLoader.configPath) + if (lastContent !== "" && currentContent !== lastContent) { + console.log("Config file changed, reloading...") + loadConfig() + configLoader.folderChanged() + } + lastContent = currentContent + } catch (e) { + // File might have been deleted, ignore + } + } + } + + function loadConfig() { + try { + let configText = Qt.readFile(configPath) + let configData = JSON.parse(configText) + + // Replace $HOME with actual home directory + let newFolder = configData.gifFolder.replace("$HOME", StandardPaths.homeLocation) + + if (gifFolder !== newFolder && loaded) { + // Folder changed, emit signal + gifFolder = newFolder + folderChanged() + } else { + gifFolder = newFolder + } + + loaded = true + + // Initialize watcher's lastContent on first load + if (watcher.lastContent === "") { + watcher.lastContent = configText + } + } catch (e) { + console.error("Failed to load config:", e) + // Fallback to default path + gifFolder = StandardPaths.homeLocation + "/.config/quickshell/QtDesktopPet/Gifs" + loaded = true + } + } + + Component.onCompleted: { + // Start the check/create chain + dirCheckProcess.running = true + } +} diff --git a/Modules/GetGifs.qml b/Modules/GetGifs.qml index b0cbf43..42195c1 100644 --- a/Modules/GetGifs.qml +++ b/Modules/GetGifs.qml @@ -2,12 +2,32 @@ import Quickshell.Io Process { id: getGifsProcess + required property string gifFolder property list gifsList: [] - command: ["sh", "-c", "$HOME/.config/quickshell/QtDesktopPet/Scripts/files.sh"] + + command: ["find", gifFolder, "-type", "f", "-name", "*.gif"] + stdout: StdioCollector { onStreamFinished: { var gifs = this.text.trim().split("\n") - getGifsProcess.gifsList = gifs + if (gifs.length > 0 && gifs[0] !== "") { + getGifsProcess.gifsList = gifs + } else { + getGifsProcess.gifsList = [] + } + } + } + + function reload() { + // Clear current list and restart the process + gifsList = [] + running = false + running = true + } + + onGifFolderChanged: { + if (running) { + reload() } } } diff --git a/Modules/GifsLoader.qml b/Modules/GifsLoader.qml index f904d9b..41d4bb5 100644 --- a/Modules/GifsLoader.qml +++ b/Modules/GifsLoader.qml @@ -8,10 +8,11 @@ Repeater { property int lastWidth model: gifsList Item { - x: gifRepeater.itemAt(index - 1).x + gifRepeater.itemAt(index - 1).width + x: index === 0 ? 0 : gifRepeater.itemAt(index - 1).x + gifRepeater.itemAt(index - 1).width y: Screen.height - height width: gif.width height: gif.height + AnimatedImage { id: gif source: modelData diff --git a/Scripts/files.sh b/Scripts/files.sh deleted file mode 100755 index 6ba90c5..0000000 --- a/Scripts/files.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/zsh - -find "$HOME/.config/quickshell/QtDesktopPet/Gifs/" -type f diff --git a/shell.qml b/shell.qml index 2eeb4c6..796c1e2 100644 --- a/shell.qml +++ b/shell.qml @@ -27,11 +27,20 @@ PanelWindow { bottom: 9 } + ConfigLoader { + id: configLoader + onFolderChanged: { + console.log("Folder changed to:", gifFolder) + getGifs.reload() + } + } + GetGifs { id: getGifs - running: true + gifFolder: configLoader.gifFolder + running: configLoader.loaded } - + GifsLoader { id: gifloader gifsList: getGifs.gifsList