fix: use private constructor for singleton

This commit is contained in:
2 * r + 2 * t 2026-04-11 02:52:17 +10:00
parent 8d73d6037d
commit f7aec30ad2
2 changed files with 13 additions and 7 deletions

View file

@ -4,12 +4,14 @@
namespace caelestia::config {
static GlobalConfig* s_instance = nullptr;
namespace {
static QString configDir() {
QString configDir() {
return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/caelestia/");
}
} // namespace
GlobalConfig::GlobalConfig(QObject* parent)
: ConfigObject(parent)
, m_appearance(new AppearanceConfig(this))
@ -30,8 +32,6 @@ GlobalConfig::GlobalConfig(QObject* parent)
, m_services(new ServiceConfig(this))
, m_paths(new UserPaths(this))
, m_advanced(new AdvancedConfig(this)) {
s_instance = this;
// Bind token base values from advanced config to appearance computed properties
auto* adv = m_advanced->appearance();
m_appearance->rounding()->bindTokens(adv->rounding());
@ -46,7 +46,12 @@ GlobalConfig::GlobalConfig(QObject* parent)
}
GlobalConfig* GlobalConfig::instance() {
return s_instance;
static GlobalConfig instance;
return &instance;
}
GlobalConfig* GlobalConfig::create(QQmlEngine*, QJSEngine*) {
return instance();
}
void GlobalConfig::save() {

View file

@ -50,9 +50,8 @@ class GlobalConfig : public ConfigObject {
Q_PROPERTY(AdvancedConfig* advanced READ advanced CONSTANT)
public:
explicit GlobalConfig(QObject* parent = nullptr);
static GlobalConfig* instance();
static GlobalConfig* create(QQmlEngine*, QJSEngine*);
[[nodiscard]] AdvancedConfig* advanced() const { return m_advanced; }
@ -60,6 +59,8 @@ public:
Q_INVOKABLE void reload();
private:
explicit GlobalConfig(QObject* parent = nullptr);
AdvancedConfig* m_advanced = nullptr;
};