-
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.
feat(LoginPage): perform network checks before Login/Sync
- expose the `checking` property from the C++ backend, fix it in order not to start when `!active` - display an additional popup when net checks enabled and we are not online
- Loading branch information
Showing
6 changed files
with
178 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,51 @@ | ||
#pragma once | ||
|
||
#include <QNetworkAccessManager> | ||
#include <QNetworkReply> | ||
#include <QObject> | ||
#include <QQmlParserStatus> | ||
#include <QTimer> | ||
|
||
#include <chrono> | ||
|
||
using namespace std::chrono_literals; | ||
class QNetworkAccessManager; | ||
|
||
/// 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 | ||
/// It checks the connection every 30 seconds as long as the \c active property is \c true (by default it is) | ||
class NetworkChecker : public QObject, public QQmlParserStatus | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged) | ||
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) | ||
Q_INTERFACES(QQmlParserStatus) | ||
|
||
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged FINAL) | ||
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL) | ||
Q_PROPERTY(bool checking READ checking NOTIFY checkingChanged FINAL) | ||
|
||
public: | ||
explicit NetworkChecker(QObject* parent = nullptr); | ||
explicit NetworkChecker(QObject *parent = nullptr); | ||
bool isOnline() const; | ||
|
||
bool isActive() const; | ||
void setActive(bool active); | ||
|
||
Q_INVOKABLE void checkNetwork(); | ||
|
||
protected: | ||
void classBegin() override; | ||
void componentComplete() override; | ||
|
||
signals: | ||
void isOnlineChanged(bool online); | ||
void activeChanged(bool active); | ||
void checkingChanged(); | ||
|
||
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 onFinished(QNetworkReply *reply); | ||
void updateRegularCheck(bool active); | ||
}; | ||
|
||
bool m_checking{false}; | ||
bool checking() const; | ||
void setChecking(bool checking); | ||
}; |
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