From 8daa1702d080c3f11d81c53030e65cf1076f3d22 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Fri, 16 May 2025 16:02:05 +0200 Subject: [PATCH] refractor xdg dirs --- .config/quickshell/modules/common/XdgDirectories.qml | 12 ++++++++++++ .config/quickshell/modules/overview/SearchWidget.qml | 2 +- .config/quickshell/modules/sidebarLeft/AiChat.qml | 3 +-- .config/quickshell/modules/sidebarLeft/Anime.qml | 6 +++--- .../modules/sidebarLeft/anime/BooruImage.qml | 2 +- .config/quickshell/services/Ai.qml | 3 +-- .config/quickshell/services/ConfigLoader.qml | 2 +- .config/quickshell/services/LatexRenderer.qml | 2 +- .config/quickshell/services/MaterialThemeLoader.qml | 3 +-- .config/quickshell/services/Notifications.qml | 5 +++-- .../quickshell/services/PersistentStateManager.qml | 2 +- .config/quickshell/services/Todo.qml | 3 ++- 12 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 .config/quickshell/modules/common/XdgDirectories.qml diff --git a/.config/quickshell/modules/common/XdgDirectories.qml b/.config/quickshell/modules/common/XdgDirectories.qml new file mode 100644 index 00000000..51bf2d0c --- /dev/null +++ b/.config/quickshell/modules/common/XdgDirectories.qml @@ -0,0 +1,12 @@ +import Qt.labs.platform +import QtQuick +import Quickshell +pragma Singleton +pragma ComponentBehavior: Bound + +Singleton { + readonly property string config: StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0] + readonly property string state: StandardPaths.standardLocations(StandardPaths.StateLocation)[0] + readonly property string cache: StandardPaths.standardLocations(StandardPaths.CacheLocation)[0] + readonly property string pictures: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] +} diff --git a/.config/quickshell/modules/overview/SearchWidget.qml b/.config/quickshell/modules/overview/SearchWidget.qml index 7292e30b..3be7b915 100644 --- a/.config/quickshell/modules/overview/SearchWidget.qml +++ b/.config/quickshell/modules/overview/SearchWidget.qml @@ -15,7 +15,7 @@ import Quickshell.Hyprland Item { // Wrapper id: root required property var panelWindow - readonly property string xdgConfigHome: StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0] + readonly property string xdgConfigHome: XdgDirectories.config property string searchingText: "" property bool showResults: searchingText != "" property real searchBarHeight: searchBar.height + Appearance.sizes.elevationMargin * 2 diff --git a/.config/quickshell/modules/sidebarLeft/AiChat.qml b/.config/quickshell/modules/sidebarLeft/AiChat.qml index fe75ac66..dba4fefa 100644 --- a/.config/quickshell/modules/sidebarLeft/AiChat.qml +++ b/.config/quickshell/modules/sidebarLeft/AiChat.qml @@ -6,7 +6,6 @@ import "./aiChat/" import "root:/modules/common/functions/fuzzysort.js" as Fuzzy import "root:/modules/common/functions/string_utils.js" as StringUtils import "root:/modules/common/functions/file_utils.js" as FileUtils -import Qt.labs.platform import QtQuick import QtQuick.Controls import QtQuick.Layouts @@ -21,7 +20,7 @@ Item { property var inputField: messageInputField readonly property var messages: Ai.messages property string commandPrefix: "/" - property string faviconDownloadPath: FileUtils.trimFileProtocol(`${StandardPaths.standardLocations(StandardPaths.CacheLocation)[0]}/media/favicons`) + property string faviconDownloadPath: FileUtils.trimFileProtocol(`${XdgDirectories.cache}/media/favicons`) property var suggestionQuery: "" property var suggestionList: [] diff --git a/.config/quickshell/modules/sidebarLeft/Anime.qml b/.config/quickshell/modules/sidebarLeft/Anime.qml index 523d2252..29b571b4 100644 --- a/.config/quickshell/modules/sidebarLeft/Anime.qml +++ b/.config/quickshell/modules/sidebarLeft/Anime.qml @@ -19,9 +19,9 @@ Item { property var panelWindow property var inputField: tagInputField readonly property var responses: Booru.responses - property string previewDownloadPath: `${StandardPaths.standardLocations(StandardPaths.CacheLocation)[0]}/media/waifus`.replace("file://", "") - property string downloadPath: (StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] + "/homework").replace("file://", "") - property string nsfwPath: (StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] + "/homework/🌶️").replace("file://", "") + property string previewDownloadPath: `${XdgDirectories.cache}/media/waifus`.replace("file://", "") + property string downloadPath: (XdgDirectories.pictures + "/homework").replace("file://", "") + property string nsfwPath: (XdgDirectories.pictures + "/homework/🌶️").replace("file://", "") property string commandPrefix: "/" property real scrollOnNewResponse: 100 property int tagSuggestionDelay: 210 diff --git a/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml b/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml index 673fc7b9..cdd44f19 100644 --- a/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml +++ b/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml @@ -97,7 +97,7 @@ Button { PointingHandInteraction {} StyledToolTip { - content: StringUtils.wordWrap(root.imageData.tags, root.maxTagStringLineLength) + content: `${StringUtils.wordWrap(root.imageData.tags, root.maxTagStringLineLength)}\nClick for options` } background: Rectangle { diff --git a/.config/quickshell/services/Ai.qml b/.config/quickshell/services/Ai.qml index ce9ae0b3..495f15ef 100644 --- a/.config/quickshell/services/Ai.qml +++ b/.config/quickshell/services/Ai.qml @@ -11,7 +11,6 @@ import QtQuick; Singleton { id: root - readonly property string xdgConfigHome: StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0] readonly property string interfaceRole: "interface" readonly property string apiKeyEnvVarName: "API_KEY" property Component aiMessageComponent: AiMessageData {} @@ -107,7 +106,7 @@ Singleton { Process { id: getOllamaModels - command: ["bash", "-c", `${xdgConfigHome}/quickshell/scripts/ai/show-installed-ollama-models.sh`.replace(/file:\/\//, "")] + command: ["bash", "-c", `${XdgDirectories.config}/quickshell/scripts/ai/show-installed-ollama-models.sh`.replace(/file:\/\//, "")] stdout: SplitParser { onRead: data => { try { diff --git a/.config/quickshell/services/ConfigLoader.qml b/.config/quickshell/services/ConfigLoader.qml index 1bc940d9..c05b1734 100644 --- a/.config/quickshell/services/ConfigLoader.qml +++ b/.config/quickshell/services/ConfigLoader.qml @@ -12,7 +12,7 @@ import Qt.labs.platform Singleton { id: root - property string fileDir: `${StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0]}/illogical-impulse` + property string fileDir: `${XdgDirectories.config}/illogical-impulse` property string fileName: "config.json" property string filePath: FileUtils.trimFileProtocol(`${root.fileDir}/${root.fileName}`) property bool firstLoad: true diff --git a/.config/quickshell/services/LatexRenderer.qml b/.config/quickshell/services/LatexRenderer.qml index edeaccb0..354684be 100644 --- a/.config/quickshell/services/LatexRenderer.qml +++ b/.config/quickshell/services/LatexRenderer.qml @@ -26,7 +26,7 @@ Singleton { property var processedExpressions: ({}) property var renderedImagePaths: ({}) property string microtexBinaryPath: Qt.resolvedUrl("/opt/MicroTeX/LaTeX") - property string latexOutputPath: FileUtils.trimFileProtocol(`${StandardPaths.standardLocations(StandardPaths.CacheLocation)[0]}/latex`) + property string latexOutputPath: FileUtils.trimFileProtocol(`${XdgDirectories.cache}/latex`) signal renderFinished(string hash, string imagePath) diff --git a/.config/quickshell/services/MaterialThemeLoader.qml b/.config/quickshell/services/MaterialThemeLoader.qml index c34441a1..7eb974b1 100644 --- a/.config/quickshell/services/MaterialThemeLoader.qml +++ b/.config/quickshell/services/MaterialThemeLoader.qml @@ -5,11 +5,10 @@ import "root:/modules/common" import QtQuick import Quickshell import Quickshell.Io -import Qt.labs.platform Singleton { id: root - property string filePath: `${StandardPaths.standardLocations(StandardPaths.StateLocation)[0]}/user/generated/colors.json` + property string filePath: `${XdgDirectories.state}/user/generated/colors.json` function reapplyTheme() { themeFileView.reload() diff --git a/.config/quickshell/services/Notifications.qml b/.config/quickshell/services/Notifications.qml index d04233b8..0105d33f 100644 --- a/.config/quickshell/services/Notifications.qml +++ b/.config/quickshell/services/Notifications.qml @@ -1,6 +1,7 @@ pragma Singleton pragma ComponentBehavior: Bound +import "root:/modules/common" import QtQuick import Quickshell import Quickshell.Io @@ -9,10 +10,10 @@ import Qt.labs.platform Singleton { id: root - property var filePath: `${StandardPaths.standardLocations(StandardPaths.CacheLocation)[0]}/notifications/notifications.json` + property var filePath: `${XdgDirectories.cache}/notifications/notifications.json` property var list: [] // Quickshell's notification IDs starts at 1 on each run, while saved notifications - // can already contain higher IDs. This is a workaround to avoid id collisions + // can already contain higher IDs. This is for avoiding id collisions property int idOffset signal initDone(); diff --git a/.config/quickshell/services/PersistentStateManager.qml b/.config/quickshell/services/PersistentStateManager.qml index ba23dfeb..d961b41b 100644 --- a/.config/quickshell/services/PersistentStateManager.qml +++ b/.config/quickshell/services/PersistentStateManager.qml @@ -11,7 +11,7 @@ import Qt.labs.platform Singleton { id: root - property string fileDir: `${StandardPaths.standardLocations(StandardPaths.StateLocation)[0]}` + property string fileDir: XdgDirectories.state property string fileName: "states.json" property string filePath: `${root.fileDir}/${root.fileName}` property bool allowWriteback: false diff --git a/.config/quickshell/services/Todo.qml b/.config/quickshell/services/Todo.qml index 72f8055d..cbf5e02f 100644 --- a/.config/quickshell/services/Todo.qml +++ b/.config/quickshell/services/Todo.qml @@ -1,6 +1,7 @@ pragma Singleton pragma ComponentBehavior: Bound +import "root:/modules/common" import Quickshell; import Quickshell.Io; import Qt.labs.platform @@ -8,7 +9,7 @@ import QtQuick; Singleton { id: root - property var filePath: `${StandardPaths.standardLocations(StandardPaths.StateLocation)[0]}/user/todo.json` + property var filePath: `${XdgDirectories.state}/user/todo.json` property var list: [] function addItem(item) {