Skip to content

Commit 5cf56f4

Browse files
committed
core/qmlglobal: expose cacheDir
1 parent fee4942 commit 5cf56f4

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/core/paths.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ QString QsPaths::ipcPath(const QString& id) {
5151
QDir* QsPaths::cacheDir() {
5252
if (this->cacheState == DirState::Unknown) {
5353
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
54+
dir = QDir(dir.filePath("by-shell"));
5455
dir = QDir(dir.filePath(this->shellId));
5556
this->mCacheDir = dir;
5657

src/core/qmlglobal.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "generation.hpp"
2323
#include "iconimageprovider.hpp"
24+
#include "paths.hpp"
2425
#include "qmlscreen.hpp"
2526
#include "rootwrapper.hpp"
2627

@@ -189,6 +190,14 @@ void QuickshellGlobal::setWatchFiles(bool watchFiles) { // NOLINT
189190
QuickshellSettings::instance()->setWatchFiles(watchFiles);
190191
}
191192

193+
QString QuickshellGlobal::cacheDir() const { // NOLINT
194+
auto* dir = QsPaths::instance()->cacheDir();
195+
if (dir) return dir->path();
196+
197+
qCritical() << "Could not find cache dir.";
198+
return "/quickshell-cache-not-found";
199+
}
200+
192201
QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT
193202
auto vstr = variable.toStdString();
194203
if (!qEnvironmentVariableIsSet(vstr.data())) return QVariant::fromValue(nullptr);

src/core/qmlglobal.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class QuickshellGlobal: public QObject {
108108
/// If true then the configuration will be reloaded whenever any files change.
109109
/// Defaults to true.
110110
Q_PROPERTY(bool watchFiles READ watchFiles WRITE setWatchFiles NOTIFY watchFilesChanged);
111+
/// The per-shell cache directory.
112+
///
113+
/// Usually `~/.cache/quickshell/by-shell/<shell-id>`
114+
Q_PROPERTY(QString cacheDir READ cacheDir CONSTANT);
111115
// clang-format on
112116
QML_SINGLETON;
113117
QML_NAMED_ELEMENT(Quickshell);
@@ -152,6 +156,8 @@ class QuickshellGlobal: public QObject {
152156
[[nodiscard]] bool watchFiles() const;
153157
void setWatchFiles(bool watchFiles);
154158

159+
[[nodiscard]] QString cacheDir() const;
160+
155161
static QuickshellGlobal* create(QQmlEngine* engine, QJSEngine* /*unused*/);
156162

157163
signals:

0 commit comments

Comments
 (0)