Skip to content

Commit 51df97d

Browse files
committed
qml: only write options after onboarding
1 parent abd3ba1 commit 51df97d

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
@@ -279,9 +279,8 @@ int QmlGuiMain(int argc, char* argv[])
279279
engine.rootContext()->setContextProperty("peerTableModel", &peer_model);
280280
engine.rootContext()->setContextProperty("peerListModelProxy", &peer_model_sort_proxy);
281281

282-
OptionsQmlModel options_model{*node};
282+
OptionsQmlModel options_model(*node, !need_onboarding.toBool());
283283
engine.rootContext()->setContextProperty("optionsModel", &options_model);
284-
285284
engine.rootContext()->setContextProperty("needOnboarding", need_onboarding);
286285
#ifdef __ANDROID__
287286
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
@@ -16,8 +16,9 @@
1616

1717
#include <cassert>
1818

19-
OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
19+
OptionsQmlModel::OptionsQmlModel(interfaces::Node& node, bool is_onboarded)
2020
: m_node{node}
21+
, m_onboarded{is_onboarded}
2122
{
2223
m_dbcache_size_mib = SettingToInt(m_node.getPersistentSetting("dbcache"), nDefaultDbCache);
2324

@@ -32,7 +33,9 @@ void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib)
3233
{
3334
if (new_dbcache_size_mib != m_dbcache_size_mib) {
3435
m_dbcache_size_mib = new_dbcache_size_mib;
35-
m_node.updateRwSetting("dbcache", new_dbcache_size_mib);
36+
if (m_onboarded) {
37+
m_node.updateRwSetting("dbcache", new_dbcache_size_mib);
38+
}
3639
Q_EMIT dbcacheSizeMiBChanged(new_dbcache_size_mib);
3740
}
3841
}
@@ -41,7 +44,9 @@ void OptionsQmlModel::setListen(bool new_listen)
4144
{
4245
if (new_listen != m_listen) {
4346
m_listen = new_listen;
44-
m_node.updateRwSetting("listen", new_listen);
47+
if (m_onboarded) {
48+
m_node.updateRwSetting("listen", new_listen);
49+
}
4550
Q_EMIT listenChanged(new_listen);
4651
}
4752
}
@@ -50,7 +55,9 @@ void OptionsQmlModel::setNatpmp(bool new_natpmp)
5055
{
5156
if (new_natpmp != m_natpmp) {
5257
m_natpmp = new_natpmp;
53-
m_node.updateRwSetting("natpmp", new_natpmp);
58+
if (m_onboarded) {
59+
m_node.updateRwSetting("natpmp", new_natpmp);
60+
}
5461
Q_EMIT natpmpChanged(new_natpmp);
5562
}
5663
}
@@ -59,7 +66,9 @@ void OptionsQmlModel::setPrune(bool new_prune)
5966
{
6067
if (new_prune != m_prune) {
6168
m_prune = new_prune;
62-
m_node.updateRwSetting("prune", pruneSetting());
69+
if (m_onboarded) {
70+
m_node.updateRwSetting("prune", pruneSetting());
71+
}
6372
Q_EMIT pruneChanged(new_prune);
6473
}
6574
}
@@ -68,7 +77,9 @@ void OptionsQmlModel::setPruneSizeGB(int new_prune_size_gb)
6877
{
6978
if (new_prune_size_gb != m_prune_size_gb) {
7079
m_prune_size_gb = new_prune_size_gb;
71-
m_node.updateRwSetting("prune", pruneSetting());
80+
if (m_onboarded) {
81+
m_node.updateRwSetting("prune", pruneSetting());
82+
}
7283
Q_EMIT pruneSizeGBChanged(new_prune_size_gb);
7384
}
7485
}
@@ -77,7 +88,9 @@ void OptionsQmlModel::setScriptThreads(int new_script_threads)
7788
{
7889
if (new_script_threads != m_script_threads) {
7990
m_script_threads = new_script_threads;
80-
m_node.updateRwSetting("par", new_script_threads);
91+
if (m_onboarded) {
92+
m_node.updateRwSetting("par", new_script_threads);
93+
}
8194
Q_EMIT scriptThreadsChanged(new_script_threads);
8295
}
8396
}
@@ -86,7 +99,9 @@ void OptionsQmlModel::setServer(bool new_server)
8699
{
87100
if (new_server != m_server) {
88101
m_server = new_server;
89-
m_node.updateRwSetting("server", new_server);
102+
if (m_onboarded) {
103+
m_node.updateRwSetting("server", new_server);
104+
}
90105
Q_EMIT serverChanged(new_server);
91106
}
92107
}
@@ -95,7 +110,9 @@ void OptionsQmlModel::setUpnp(bool new_upnp)
95110
{
96111
if (new_upnp != m_upnp) {
97112
m_upnp = new_upnp;
98-
m_node.updateRwSetting("upnp", new_upnp);
113+
if (m_onboarded) {
114+
m_node.updateRwSetting("upnp", new_upnp);
115+
}
99116
Q_EMIT upnpChanged(new_upnp);
100117
}
101118
}
@@ -105,3 +122,30 @@ common::SettingsValue OptionsQmlModel::pruneSetting() const
105122
assert(!m_prune || m_prune_size_gb >= 1);
106123
return m_prune ? PruneGBtoMiB(m_prune_size_gb) : 0;
107124
}
125+
126+
void OptionsQmlModel::onboard()
127+
{
128+
m_node.resetSettings();
129+
if (m_dbcache_size_mib != nDefaultDbCache) {
130+
m_node.updateRwSetting("dbcache", m_dbcache_size_mib);
131+
}
132+
if (m_listen) {
133+
m_node.updateRwSetting("listen", m_listen);
134+
}
135+
if (m_natpmp) {
136+
m_node.updateRwSetting("natpmp", m_natpmp);
137+
}
138+
if (m_prune) {
139+
m_node.updateRwSetting("prune", pruneSetting());
140+
}
141+
if (m_script_threads != DEFAULT_SCRIPTCHECK_THREADS) {
142+
m_node.updateRwSetting("par", m_script_threads);
143+
}
144+
if (m_server) {
145+
m_node.updateRwSetting("server", m_server);
146+
}
147+
if (m_upnp) {
148+
m_node.updateRwSetting("upnp", m_upnp);
149+
}
150+
m_onboarded = true;
151+
}

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)