Skip to content

Commit 1346f90

Browse files
committed
frontend/qt: react to change in connectivity status.
Instead of relying on a polling mechanism, we use QT's signals to monitor the connectivity status and react when this changes by showing a banner. When the connectivity is resumed, we trigger a reconnect to our nodes.
1 parent f4d4769 commit 1346f90

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

backend/backend.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ func NewBackend(arguments *arguments.Arguments, environment Environment) (*Backe
279279
log: log,
280280

281281
testing: backendConfig.AppConfig().Backend.StartInTestnet || arguments.Testing(),
282+
283+
// TODO: remove when connectivity check is present on all platforms
284+
isOnline: true,
282285
}
283286
// TODO: remove when connectivity check is present on all platforms
284287
backend.isOnline.Store(true)

frontends/qt/network.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
#include <QNetworkInformation>
22
#include "libserver.h"
3+
<<<<<<< HEAD
34
#include "network.h"
5+
=======
6+
>>>>>>> b8afb2139 (frontend/qt: react to change in connectivity status.)
47

58
void setupReachabilityNotifier() {
69
auto loaded = QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
710
if (!loaded) {
11+
<<<<<<< HEAD
812
goLog("can't load QNetworkInformation backend");
913
// If we can't load the backend, we can't determine whether or not to show the banner.
1014
setOnline(true);
15+
=======
16+
>>>>>>> b8afb2139 (frontend/qt: react to change in connectivity status.)
1117
return;
1218
}
1319
QNetworkInformation* info = QNetworkInformation::instance();
1420
if (info) {
1521
QObject::connect(info, &QNetworkInformation::reachabilityChanged, [](QNetworkInformation::Reachability reachability){
22+
<<<<<<< HEAD
1623
// We include Reachability::Unknown here as we prefer not include false positives. If QT can't determine whether
1724
// we are online, we do not show the banner.
1825
bool isReachable = (reachability == QNetworkInformation::Reachability::Online || reachability == QNetworkInformation::Reachability::Unknown);
1926
setOnline(isReachable);
27+
=======
28+
bool isReachable = (reachability == QNetworkInformation::Reachability::Online);
29+
onlineStatusChanged(isReachable);
30+
>>>>>>> b8afb2139 (frontend/qt: react to change in connectivity status.)
2031
});
2132
}
2233
}
2334

2435
bool isReachable() {
2536
auto loaded = QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
2637
if (!loaded) {
38+
<<<<<<< HEAD
2739
goLog("can't load QNetworkInformation backend");
2840
return true;
2941
}
@@ -33,4 +45,14 @@ bool isReachable() {
3345
}
3446
// Same as above, if we can't obtain information, we don't show any banner at all.
3547
return true;
48+
=======
49+
return false;
50+
}
51+
QNetworkInformation* info = QNetworkInformation::instance();
52+
if (info) {
53+
return info->reachability() == QNetworkInformation::Reachability::Online;
54+
} else {
55+
return false;
56+
}
57+
>>>>>>> b8afb2139 (frontend/qt: react to change in connectivity status.)
3658
}

0 commit comments

Comments
 (0)