Skip to content

Commit 61f8e6c

Browse files
committed
qml: only write options after onboarding
1 parent f8b54a8 commit 61f8e6c

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

283-
OptionsQmlModel options_model{*node};
283+
OptionsQmlModel options_model(*node, !need_onboarding.toBool());
284284
engine.rootContext()->setContextProperty("optionsModel", &options_model);
285-
286285
engine.rootContext()->setContextProperty("needOnboarding", need_onboarding);
287286
#ifdef __ANDROID__
288287
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
@@ -17,8 +17,9 @@
1717

1818
#include <cassert>
1919

20-
OptionsQmlModel::OptionsQmlModel(interfaces::Node& node)
20+
OptionsQmlModel::OptionsQmlModel(interfaces::Node& node, bool is_onboarded)
2121
: m_node{node}
22+
, m_onboarded{is_onboarded}
2223
{
2324
m_dbcache_size_mib = SettingToInt(m_node.getPersistentSetting("dbcache"), nDefaultDbCache);
2425

@@ -41,7 +42,9 @@ void OptionsQmlModel::setDbcacheSizeMiB(int new_dbcache_size_mib)
4142
{
4243
if (new_dbcache_size_mib != m_dbcache_size_mib) {
4344
m_dbcache_size_mib = new_dbcache_size_mib;
44-
m_node.updateRwSetting("dbcache", new_dbcache_size_mib);
45+
if (m_onboarded) {
46+
m_node.updateRwSetting("dbcache", new_dbcache_size_mib);
47+
}
4548
Q_EMIT dbcacheSizeMiBChanged(new_dbcache_size_mib);
4649
}
4750
}
@@ -50,7 +53,9 @@ void OptionsQmlModel::setListen(bool new_listen)
5053
{
5154
if (new_listen != m_listen) {
5255
m_listen = new_listen;
53-
m_node.updateRwSetting("listen", new_listen);
56+
if (m_onboarded) {
57+
m_node.updateRwSetting("listen", new_listen);
58+
}
5459
Q_EMIT listenChanged(new_listen);
5560
}
5661
}
@@ -59,7 +64,9 @@ void OptionsQmlModel::setNatpmp(bool new_natpmp)
5964
{
6065
if (new_natpmp != m_natpmp) {
6166
m_natpmp = new_natpmp;
62-
m_node.updateRwSetting("natpmp", new_natpmp);
67+
if (m_onboarded) {
68+
m_node.updateRwSetting("natpmp", new_natpmp);
69+
}
6370
Q_EMIT natpmpChanged(new_natpmp);
6471
}
6572
}
@@ -68,7 +75,9 @@ void OptionsQmlModel::setPrune(bool new_prune)
6875
{
6976
if (new_prune != m_prune) {
7077
m_prune = new_prune;
71-
m_node.updateRwSetting("prune", pruneSetting());
78+
if (m_onboarded) {
79+
m_node.updateRwSetting("prune", pruneSetting());
80+
}
7281
Q_EMIT pruneChanged(new_prune);
7382
}
7483
}
@@ -77,7 +86,9 @@ void OptionsQmlModel::setPruneSizeGB(int new_prune_size_gb)
7786
{
7887
if (new_prune_size_gb != m_prune_size_gb) {
7988
m_prune_size_gb = new_prune_size_gb;
80-
m_node.updateRwSetting("prune", pruneSetting());
89+
if (m_onboarded) {
90+
m_node.updateRwSetting("prune", pruneSetting());
91+
}
8192
Q_EMIT pruneSizeGBChanged(new_prune_size_gb);
8293
}
8394
}
@@ -86,7 +97,9 @@ void OptionsQmlModel::setScriptThreads(int new_script_threads)
8697
{
8798
if (new_script_threads != m_script_threads) {
8899
m_script_threads = new_script_threads;
89-
m_node.updateRwSetting("par", new_script_threads);
100+
if (m_onboarded) {
101+
m_node.updateRwSetting("par", new_script_threads);
102+
}
90103
Q_EMIT scriptThreadsChanged(new_script_threads);
91104
}
92105
}
@@ -95,7 +108,9 @@ void OptionsQmlModel::setServer(bool new_server)
95108
{
96109
if (new_server != m_server) {
97110
m_server = new_server;
98-
m_node.updateRwSetting("server", new_server);
111+
if (m_onboarded) {
112+
m_node.updateRwSetting("server", new_server);
113+
}
99114
Q_EMIT serverChanged(new_server);
100115
}
101116
}
@@ -104,7 +119,9 @@ void OptionsQmlModel::setUpnp(bool new_upnp)
104119
{
105120
if (new_upnp != m_upnp) {
106121
m_upnp = new_upnp;
107-
m_node.updateRwSetting("upnp", new_upnp);
122+
if (m_onboarded) {
123+
m_node.updateRwSetting("upnp", new_upnp);
124+
}
108125
Q_EMIT upnpChanged(new_upnp);
109126
}
110127
}
@@ -114,3 +131,30 @@ common::SettingsValue OptionsQmlModel::pruneSetting() const
114131
assert(!m_prune || m_prune_size_gb >= 1);
115132
return m_prune ? PruneGBtoMiB(m_prune_size_gb) : 0;
116133
}
134+
135+
void OptionsQmlModel::onboard()
136+
{
137+
m_node.resetSettings();
138+
if (m_dbcache_size_mib != nDefaultDbCache) {
139+
m_node.updateRwSetting("dbcache", m_dbcache_size_mib);
140+
}
141+
if (m_listen) {
142+
m_node.updateRwSetting("listen", m_listen);
143+
}
144+
if (m_natpmp) {
145+
m_node.updateRwSetting("natpmp", m_natpmp);
146+
}
147+
if (m_prune) {
148+
m_node.updateRwSetting("prune", pruneSetting());
149+
}
150+
if (m_script_threads != DEFAULT_SCRIPTCHECK_THREADS) {
151+
m_node.updateRwSetting("par", m_script_threads);
152+
}
153+
if (m_server) {
154+
m_node.updateRwSetting("server", m_server);
155+
}
156+
if (m_upnp) {
157+
m_node.updateRwSetting("upnp", m_upnp);
158+
}
159+
m_onboarded = true;
160+
}

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)