fix: crash/block on qml engine reload
This commit is contained in:
parent
ff1bde855e
commit
4ff97c8306
2 changed files with 18 additions and 5 deletions
|
|
@ -1,11 +1,14 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
|
||||||
|
#include <qqmlengine.h>
|
||||||
#include <qstandardpaths.h>
|
#include <qstandardpaths.h>
|
||||||
|
|
||||||
namespace caelestia::config {
|
namespace caelestia::config {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
GlobalConfig* s_instance = nullptr;
|
||||||
|
|
||||||
QString configDir() {
|
QString configDir() {
|
||||||
return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/caelestia/");
|
return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/caelestia/");
|
||||||
}
|
}
|
||||||
|
|
@ -32,6 +35,9 @@ GlobalConfig::GlobalConfig(QObject* parent)
|
||||||
, m_services(new ServiceConfig(this))
|
, m_services(new ServiceConfig(this))
|
||||||
, m_paths(new UserPaths(this))
|
, m_paths(new UserPaths(this))
|
||||||
, m_advanced(new AdvancedConfig(this)) {
|
, m_advanced(new AdvancedConfig(this)) {
|
||||||
|
// Set global instance
|
||||||
|
s_instance = this;
|
||||||
|
|
||||||
// Bind token base values from advanced config to appearance computed properties
|
// Bind token base values from advanced config to appearance computed properties
|
||||||
auto* adv = m_advanced->appearance();
|
auto* adv = m_advanced->appearance();
|
||||||
m_appearance->rounding()->bindTokens(adv->rounding());
|
m_appearance->rounding()->bindTokens(adv->rounding());
|
||||||
|
|
@ -45,13 +51,18 @@ GlobalConfig::GlobalConfig(QObject* parent)
|
||||||
m_advanced->setupFileBackend(configDir() + QStringLiteral("advanced.json"));
|
m_advanced->setupFileBackend(configDir() + QStringLiteral("advanced.json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalConfig* GlobalConfig::instance() {
|
GlobalConfig::~GlobalConfig() {
|
||||||
static GlobalConfig instance;
|
// Clear global instance
|
||||||
return &instance;
|
s_instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalConfig* GlobalConfig::create(QQmlEngine*, QJSEngine*) {
|
GlobalConfig* GlobalConfig::instance() {
|
||||||
return instance();
|
return s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalConfig* GlobalConfig::create(QQmlEngine* engine, QJSEngine*) {
|
||||||
|
auto* config = new GlobalConfig(engine);
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalConfig::save() {
|
void GlobalConfig::save() {
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,8 @@ public:
|
||||||
Q_INVOKABLE void save();
|
Q_INVOKABLE void save();
|
||||||
Q_INVOKABLE void reload();
|
Q_INVOKABLE void reload();
|
||||||
|
|
||||||
|
~GlobalConfig() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GlobalConfig(QObject* parent = nullptr);
|
explicit GlobalConfig(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue