core/qmlglobal: expose cacheDir
This commit is contained in:
parent
fee4942771
commit
5cf56f46ea
3 changed files with 16 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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/<shell-id>`
|
||||
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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue