forked from quickshell/quickshell
core/qmlglobal: expose cacheDir
This commit is contained in:
parent
fee4942771
commit
69c7f4fe77
3 changed files with 16 additions and 0 deletions
|
@ -51,6 +51,7 @@ QString QsPaths::ipcPath(const QString& id) {
|
||||||
QDir* QsPaths::cacheDir() {
|
QDir* QsPaths::cacheDir() {
|
||||||
if (this->cacheState == DirState::Unknown) {
|
if (this->cacheState == DirState::Unknown) {
|
||||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||||
|
dir = QDir(dir.filePath("by-shell"));
|
||||||
dir = QDir(dir.filePath(this->shellId));
|
dir = QDir(dir.filePath(this->shellId));
|
||||||
this->mCacheDir = dir;
|
this->mCacheDir = dir;
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "generation.hpp"
|
#include "generation.hpp"
|
||||||
#include "iconimageprovider.hpp"
|
#include "iconimageprovider.hpp"
|
||||||
|
#include "paths.hpp"
|
||||||
#include "qmlscreen.hpp"
|
#include "qmlscreen.hpp"
|
||||||
#include "rootwrapper.hpp"
|
#include "rootwrapper.hpp"
|
||||||
|
|
||||||
|
@ -189,6 +190,14 @@ void QuickshellGlobal::setWatchFiles(bool watchFiles) { // NOLINT
|
||||||
QuickshellSettings::instance()->setWatchFiles(watchFiles);
|
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
|
QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT
|
||||||
auto vstr = variable.toStdString();
|
auto vstr = variable.toStdString();
|
||||||
if (!qEnvironmentVariableIsSet(vstr.data())) return QVariant::fromValue(nullptr);
|
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.
|
/// If true then the configuration will be reloaded whenever any files change.
|
||||||
/// Defaults to true.
|
/// Defaults to true.
|
||||||
Q_PROPERTY(bool watchFiles READ watchFiles WRITE setWatchFiles NOTIFY watchFilesChanged);
|
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
|
// clang-format on
|
||||||
QML_SINGLETON;
|
QML_SINGLETON;
|
||||||
QML_NAMED_ELEMENT(Quickshell);
|
QML_NAMED_ELEMENT(Quickshell);
|
||||||
|
@ -152,6 +156,8 @@ public:
|
||||||
[[nodiscard]] bool watchFiles() const;
|
[[nodiscard]] bool watchFiles() const;
|
||||||
void setWatchFiles(bool watchFiles);
|
void setWatchFiles(bool watchFiles);
|
||||||
|
|
||||||
|
[[nodiscard]] QString cacheDir() const;
|
||||||
|
|
||||||
static QuickshellGlobal* create(QQmlEngine* engine, QJSEngine* /*unused*/);
|
static QuickshellGlobal* create(QQmlEngine* engine, QJSEngine* /*unused*/);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue