Only start the reconnect timer once
parent
608c02799c
commit
7455d9ba23
|
|
@ -70,6 +70,15 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent)
|
|||
});
|
||||
|
||||
updateActiveBearers();
|
||||
|
||||
m_reconnectTimer.setInterval(1000);
|
||||
m_reconnectTimer.setSingleShot(true);
|
||||
connect(&m_reconnectTimer, &QTimer::timeout, this, [this](){
|
||||
if (m_currentHost) {
|
||||
qCInfo(dcNymeaConnection()) << "Reconnecting...";
|
||||
connectInternal(m_currentHost);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
NymeaConnection::BearerTypes NymeaConnection::availableBearerTypes() const
|
||||
|
|
@ -234,12 +243,7 @@ void NymeaConnection::onError(QAbstractSocket::SocketError error)
|
|||
emit connectionStatusChanged();
|
||||
|
||||
if (m_connectionStatus != ConnectionStatusSslUntrusted) {
|
||||
QTimer::singleShot(1000, this, [this](){
|
||||
if (m_currentHost) {
|
||||
qCInfo(dcNymeaConnection()) << "Reconnecting...";
|
||||
connectInternal(m_currentHost);
|
||||
}
|
||||
});
|
||||
m_reconnectTimer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#include <QAbstractSocket>
|
||||
#include <QUrl>
|
||||
#include <QNetworkConfigurationManager>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "nymeahost.h"
|
||||
|
||||
|
|
@ -139,6 +139,8 @@ private:
|
|||
NymeaTransportInterface *m_currentTransport = nullptr;
|
||||
NymeaHost *m_currentHost = nullptr;
|
||||
Connection *m_preferredConnection = nullptr;
|
||||
|
||||
QTimer m_reconnectTimer;
|
||||
};
|
||||
|
||||
#endif // NYMEACONNECTION_H
|
||||
|
|
|
|||
|
|
@ -38,12 +38,15 @@ NymeaHost::NymeaHost(QObject *parent):
|
|||
{
|
||||
connect(m_connections, &Connections::dataChanged, this, [this](const QModelIndex &, const QModelIndex &, const QVector<int>){
|
||||
emit connectionChanged();
|
||||
syncOnlineState();
|
||||
});
|
||||
connect(m_connections, &Connections::connectionAdded, this, [this](Connection*){
|
||||
emit connectionChanged();
|
||||
syncOnlineState();
|
||||
});
|
||||
connect(m_connections, &Connections::connectionRemoved, this, [this](Connection*){
|
||||
emit connectionChanged();
|
||||
syncOnlineState();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +96,28 @@ Connections* NymeaHost::connections() const
|
|||
return m_connections;
|
||||
}
|
||||
|
||||
bool NymeaHost::online() const
|
||||
{
|
||||
return m_online;
|
||||
}
|
||||
|
||||
void NymeaHost::syncOnlineState()
|
||||
{
|
||||
for (int i = 0; i < m_connections->rowCount(); i++) {
|
||||
if (m_connections->get(i)->online()) {
|
||||
if (!m_online) {
|
||||
m_online = true;
|
||||
emit onlineChanged();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (m_online) {
|
||||
m_online = false;
|
||||
emit onlineChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Connections::Connections(QObject *parent):
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ class NymeaHost: public QObject
|
|||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||
Q_PROPERTY(QString version READ version NOTIFY versionChanged)
|
||||
Q_PROPERTY(Connections* connections READ connections CONSTANT)
|
||||
Q_PROPERTY(bool online READ online NOTIFY onlineChanged)
|
||||
|
||||
public:
|
||||
explicit NymeaHost(QObject *parent = nullptr);
|
||||
|
|
@ -153,16 +154,23 @@ public:
|
|||
|
||||
Connections *connections() const;
|
||||
|
||||
bool online() const;
|
||||
|
||||
signals:
|
||||
void nameChanged();
|
||||
void versionChanged();
|
||||
void connectionChanged();
|
||||
void onlineChanged();
|
||||
|
||||
private:
|
||||
void syncOnlineState();
|
||||
|
||||
private:
|
||||
QUuid m_uuid;
|
||||
QString m_name;
|
||||
QString m_version;
|
||||
Connections *m_connections = nullptr;
|
||||
bool m_online = false;
|
||||
};
|
||||
|
||||
#endif // NYMEAHOST_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue