core/qmlglobal: add dataPath(), statePath() and cachePath()

This commit is contained in:
outfoxxed 2025-05-16 20:33:40 -07:00
parent c1c24c2998
commit a05c0de53b
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
3 changed files with 30 additions and 0 deletions

View file

@ -11,6 +11,7 @@
#include <qloggingcategory.h>
#include <qstandardpaths.h>
#include <qtenvironmentvariables.h>
#include <qtversionchecks.h>
#include <unistd.h>
#include "instanceinfo.hpp"
@ -232,7 +233,18 @@ QDir QsPaths::shellDataDir() {
QDir QsPaths::shellStateDir() {
if (this->shellStateState == DirState::Unknown) {
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
QDir dir;
if (qEnvironmentVariableIsSet("XDG_STATE_HOME")) {
dir = QDir(qEnvironmentVariable("XDG_STATE_HOME"));
} else {
auto home = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
dir = QDir(home.filePath(".local/state"));
}
#else
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::StateLocation));
#endif
dir = QDir(dir.filePath("by-shell"));
dir = QDir(dir.filePath(this->shellId));
this->mShellStateDir = dir;