diff --git a/src/core/paths.cpp b/src/core/paths.cpp index 0129d884..211d57c1 100644 --- a/src/core/paths.cpp +++ b/src/core/paths.cpp @@ -51,6 +51,7 @@ QString QsPaths::ipcPath(const QString& id) { QDir* QsPaths::cacheDir() { if (this->cacheState == DirState::Unknown) { auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); + dir = QDir(dir.filePath("by-shell")); dir = QDir(dir.filePath(this->shellId)); this->mCacheDir = dir; diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index 23f238da..0b976053 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -21,6 +21,7 @@ #include "generation.hpp" #include "iconimageprovider.hpp" +#include "paths.hpp" #include "qmlscreen.hpp" #include "rootwrapper.hpp" @@ -189,6 +190,14 @@ void QuickshellGlobal::setWatchFiles(bool watchFiles) { // NOLINT QuickshellSettings::instance()->setWatchFiles(watchFiles); } +QString QuickshellGlobal::cacheDir() const { // NOLINT + auto* dir = QsPaths::instance()->cacheDir(); + if (dir) return dir->path(); + + qCritical() << "Could not find cache dir."; + return "/quickshell-cache-not-found"; +} + QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT auto vstr = variable.toStdString(); if (!qEnvironmentVariableIsSet(vstr.data())) return QVariant::fromValue(nullptr); diff --git a/src/core/qmlglobal.hpp b/src/core/qmlglobal.hpp index 4f46d238..2f614fe7 100644 --- a/src/core/qmlglobal.hpp +++ b/src/core/qmlglobal.hpp @@ -108,6 +108,10 @@ class QuickshellGlobal: public QObject { /// If true then the configuration will be reloaded whenever any files change. /// Defaults to true. Q_PROPERTY(bool watchFiles READ watchFiles WRITE setWatchFiles NOTIFY watchFilesChanged); + /// The per-shell cache directory. + /// + /// Usually `~/.cache/quickshell/by-shell/` + Q_PROPERTY(QString cacheDir READ cacheDir CONSTANT); // clang-format on QML_SINGLETON; QML_NAMED_ELEMENT(Quickshell); @@ -152,6 +156,8 @@ public: [[nodiscard]] bool watchFiles() const; void setWatchFiles(bool watchFiles); + [[nodiscard]] QString cacheDir() const; + static QuickshellGlobal* create(QQmlEngine* engine, QJSEngine* /*unused*/); signals: