refactor: Settings store envvar checks so they only need to be read once when checking

This commit is contained in:
sithlord48
2025-11-14 09:03:59 -05:00
committed by Chris Rizzitello
parent 204a6cca8a
commit 1a9e468c86

View File

@ -58,8 +58,8 @@ Settings::Settings(QObject *parent) : QObject(parent)
if (QFile(portableFile).exists())
fileToLoad = portableFile;
#else
if (!qEnvironmentVariable("XDG_CONFIG_HOME").isEmpty())
fileToLoad = QStringLiteral("%1/%2/%2.conf").arg(qEnvironmentVariable("XDG_CONFIG_HOME"), kAppName);
if (const auto xdgConfigHome = qEnvironmentVariable("XDG_CONFIG_HOME"); !xdgConfigHome.isEmpty())
fileToLoad = QStringLiteral("%1/%2/%2.conf").arg(xdgConfigHome, kAppName);
#endif
else if (QFile(UserSettingFile).exists())
fileToLoad = UserSettingFile;
@ -73,8 +73,9 @@ Settings::Settings(QObject *parent) : QObject(parent)
m_settingsProxy->load(fileToLoad);
qInfo().noquote() << "initial settings file:" << m_settings->fileName();
const auto stateBase = !qEnvironmentVariable("XDG_STATE_HOME").isEmpty()
? qEnvironmentVariable("XDG_STATE_HOME")
const auto xdgStateHome = qEnvironmentVariable("XDG_STATE_HOME");
const auto stateBase = !xdgStateHome.isEmpty()
? xdgStateHome
: QStandardPaths::standardLocations(QStandardPaths::GenericStateLocation).at(0);
const auto stateFile = QStringLiteral("%1/%2.state").arg(stateBase, kAppName);