-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dapps) Wallet Connect internet connection reestablishing issue
Add a new NetworkChecker QObject to StatusQ to be used in checking internet connection status. This is used by the WebEngineLoader to only allow loading of web pages when there is an active internet to cover for a corner case on MacOS where the internet connection is not reestablished if the WebEngineView was loaded without an active internet connection. Closes: #15598, #15806
- Loading branch information
1 parent
f226b47
commit 721f1bb
Showing
11 changed files
with
191 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <QNetworkAccessManager> | ||
#include <QNetworkReply> | ||
#include <QObject> | ||
#include <QTimer> | ||
|
||
#include <chrono> | ||
|
||
using namespace std::chrono_literals; | ||
|
||
/// Checks if the internet connection is available, when active. | ||
/// It checks the connection every 30 seconds as long as the \c active property is \c true. | ||
class NetworkChecker : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged) | ||
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) | ||
|
||
public: | ||
explicit NetworkChecker(QObject* parent = nullptr); | ||
bool isOnline() const; | ||
|
||
bool isActive() const; | ||
void setActive(bool active); | ||
|
||
signals: | ||
void isOnlineChanged(bool online); | ||
void activeChanged(bool active); | ||
|
||
private: | ||
QNetworkAccessManager manager; | ||
QTimer timer; | ||
bool online = false; | ||
bool active = true; | ||
constexpr static std::chrono::milliseconds checkInterval = 30s; | ||
|
||
void checkNetwork(); | ||
void onFinished(QNetworkReply* reply); | ||
void updateRegularCheck(bool active); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "StatusQ/networkchecker.h" | ||
|
||
NetworkChecker::NetworkChecker(QObject* parent) | ||
: QObject(parent) | ||
{ | ||
connect(&manager, &QNetworkAccessManager::finished, this, &NetworkChecker::onFinished); | ||
connect(&timer, &QTimer::timeout, this, &NetworkChecker::checkNetwork); | ||
|
||
updateRegularCheck(active); | ||
} | ||
|
||
bool NetworkChecker::isOnline() const | ||
{ | ||
return online; | ||
} | ||
|
||
void NetworkChecker::checkNetwork() | ||
{ | ||
QNetworkRequest request(QUrl("https://fedoraproject.org/static/hotspot.txt")); | ||
manager.get(request); | ||
} | ||
|
||
void NetworkChecker::onFinished(QNetworkReply* reply) | ||
{ | ||
bool wasOnline = online; | ||
online = (reply->error() == QNetworkReply::NoError); | ||
reply->deleteLater(); | ||
|
||
if(wasOnline != online) | ||
{ | ||
emit isOnlineChanged(online); | ||
} | ||
} | ||
|
||
bool NetworkChecker::isActive() const | ||
{ | ||
return active; | ||
} | ||
|
||
void NetworkChecker::setActive(bool active) | ||
{ | ||
if(active == this->active) return; | ||
|
||
this->active = active; | ||
emit activeChanged(active); | ||
|
||
updateRegularCheck(active); | ||
} | ||
|
||
void NetworkChecker::updateRegularCheck(bool active) | ||
{ | ||
if(active) | ||
{ | ||
checkNetwork(); | ||
timer.start(checkInterval); | ||
} | ||
else | ||
{ | ||
timer.stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters