Skip to content

Commit 08be85b

Browse files
committed
qml: only write options after onboarding
1 parent 960490b commit 08be85b

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

src/qml/bitcoin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,8 @@ int QmlGuiMain(int argc, char* argv[])
265265
engine.rootContext()->setContextProperty("peerTableModel", &peer_model);
266266
engine.rootContext()->setContextProperty("peerListModelProxy", &peer_model_sort_proxy);
267267

268-
OptionsQmlModel options_model{*node};
268+
OptionsQmlModel options_model(*node, !need_onboarding.toBool());
269269
engine.rootContext()->setContextProperty("optionsModel", &options_model);
270-
271270
engine.rootContext()->setContextProperty("needOnboarding", need_onboarding);
272271
#ifdef __ANDROID__
273272
AppMode app_mode(AppMode::MOBILE);

src/qml/models/options_model.cpp

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
#include <cassert>
1717

18-
OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
18+
OptionsQmlModel::OptionsQmlModel(interfaces::Node& node, bool is_onboarded)
1919
: m_node{node}
20+
, m_onboarded{is_onboarded}
2021
{
2122
m_dbcache_size_mib = SettingToInt(m_node.getPersistentSetting("dbcache"), nDefaultDbCache);
2223

@@ -31,7 +32,9 @@ void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib)
3132
{
3233
if (new_dbcache_size_mib != m_dbcache_size_mib) {
3334
m_dbcache_size_mib = new_dbcache_size_mib;
34-
m_node.updateRwSetting("dbcache", new_dbcache_size_mib);
35+
if (m_onboarded) {
36+
m_node.updateRwSetting("dbcache", new_dbcache_size_mib);
37+
}
3538
Q_EMIT dbcacheSizeMiBChanged(new_dbcache_size_mib);
3639
}
3740
}
@@ -40,7 +43,9 @@ void OptionsQmlModel::setListen(bool new_listen)
4043
{
4144
if (new_listen != m_listen) {
4245
m_listen = new_listen;
43-
m_node.updateRwSetting("listen", new_listen);
46+
if (m_onboarded) {
47+
m_node.updateRwSetting("listen", new_listen);
48+
}
4449
Q_EMIT listenChanged(new_listen);
4550
}
4651
}
@@ -49,7 +54,9 @@ void OptionsQmlModel::setNatpmp(bool new_natpmp)
4954
{
5055
if (new_natpmp != m_natpmp) {
5156
m_natpmp = new_natpmp;
52-
m_node.updateRwSetting("natpmp", new_natpmp);
57+
if (m_onboarded) {
58+
m_node.updateRwSetting("natpmp", new_natpmp);
59+
}
5360
Q_EMIT natpmpChanged(new_natpmp);
5461
}
5562
}
@@ -58,7 +65,9 @@ void OptionsQmlModel::setPrune(bool new_prune)
5865
{
5966
if (new_prune != m_prune) {
6067
m_prune = new_prune;
61-
m_node.updateRwSetting("prune", pruneSetting());
68+
if (m_onboarded) {
69+
m_node.updateRwSetting("prune", pruneSetting());
70+
}
6271
Q_EMIT pruneChanged(new_prune);
6372
}
6473
}
@@ -67,7 +76,9 @@ void OptionsQmlModel::setPruneSizeGB(int new_prune_size_gb)
6776
{
6877
if (new_prune_size_gb != m_prune_size_gb) {
6978
m_prune_size_gb = new_prune_size_gb;
70-
m_node.updateRwSetting("prune", pruneSetting());
79+
if (m_onboarded) {
80+
m_node.updateRwSetting("prune", pruneSetting());
81+
}
7182
Q_EMIT pruneSizeGBChanged(new_prune_size_gb);
7283
}
7384
}
@@ -76,7 +87,9 @@ void OptionsQmlModel::setScriptThreads(int new_script_threads)
7687
{
7788
if (new_script_threads != m_script_threads) {
7889
m_script_threads = new_script_threads;
79-
m_node.updateRwSetting("par", new_script_threads);
90+
if (m_onboarded) {
91+
m_node.updateRwSetting("par", new_script_threads);
92+
}
8093
Q_EMIT scriptThreadsChanged(new_script_threads);
8194
}
8295
}
@@ -85,7 +98,9 @@ void OptionsQmlModel::setServer(bool new_server)
8598
{
8699
if (new_server != m_server) {
87100
m_server = new_server;
88-
m_node.updateRwSetting("server", new_server);
101+
if (m_onboarded) {
102+
m_node.updateRwSetting("server", new_server);
103+
}
89104
Q_EMIT serverChanged(new_server);
90105
}
91106
}
@@ -94,7 +109,9 @@ void OptionsQmlModel::setUpnp(bool new_upnp)
94109
{
95110
if (new_upnp != m_upnp) {
96111
m_upnp = new_upnp;
97-
m_node.updateRwSetting("upnp", new_upnp);
112+
if (m_onboarded) {
113+
m_node.updateRwSetting("upnp", new_upnp);
114+
}
98115
Q_EMIT upnpChanged(new_upnp);
99116
}
100117
}
@@ -104,3 +121,30 @@ util::SettingsValue OptionsQmlModel::pruneSetting() const
104121
assert(!m_prune || m_prune_size_gb >= 1);
105122
return m_prune ? PruneGBtoMiB(m_prune_size_gb) : 0;
106123
}
124+
125+
void OptionsQmlModel::onboard()
126+
{
127+
m_node.resetSettings();
128+
if (m_dbcache_size_mib != nDefaultDbCache) {
129+
m_node.updateRwSetting("dbcache", m_dbcache_size_mib);
130+
}
131+
if (m_listen) {
132+
m_node.updateRwSetting("listen", m_listen);
133+
}
134+
if (m_natpmp) {
135+
m_node.updateRwSetting("natpmp", m_natpmp);
136+
}
137+
if (m_prune) {
138+
m_node.updateRwSetting("prune", pruneSetting());
139+
}
140+
if (m_script_threads != DEFAULT_SCRIPTCHECK_THREADS) {
141+
m_node.updateRwSetting("par", m_script_threads);
142+
}
143+
if (m_server) {
144+
m_node.updateRwSetting("server", m_server);
145+
}
146+
if (m_upnp) {
147+
m_node.updateRwSetting("upnp", m_upnp);
148+
}
149+
m_onboarded = true;
150+
}

src/qml/models/options_model.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class OptionsQmlModel : public QObject
3434
Q_PROPERTY(bool upnp READ upnp WRITE setUpnp NOTIFY upnpChanged)
3535

3636
public:
37-
explicit OptionsQmlModel(interfaces::Node& node);
37+
explicit OptionsQmlModel(interfaces::Node& node, bool is_onboarded);
3838

3939
int dbcacheSizeMiB() const { return m_dbcache_size_mib; }
4040
void setDbcacheSizeMiB(int new_dbcache_size_mib);
@@ -56,6 +56,7 @@ class OptionsQmlModel : public QObject
5656
void setServer(bool new_server);
5757
bool upnp() const { return m_upnp; }
5858
void setUpnp(bool new_upnp);
59+
Q_INVOKABLE void onboard();
5960

6061
Q_SIGNALS:
6162
void dbcacheSizeMiBChanged(int new_dbcache_size_mib);
@@ -69,6 +70,7 @@ class OptionsQmlModel : public QObject
6970

7071
private:
7172
interfaces::Node& m_node;
73+
bool m_onboarded;
7274

7375
// Properties that are exposed to QML.
7476
int m_dbcache_size_mib;

src/qml/pages/main.qml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ ApplicationWindow {
6666
OnboardingStorageAmount {}
6767
OnboardingConnection {}
6868

69-
onFinishedChanged: main.push(node)
69+
onFinishedChanged: {
70+
optionsModel.onboard()
71+
main.push(node)
72+
}
7073
}
7174
}
7275

0 commit comments

Comments
 (0)