From ffc4d64ae66fbf78b12a2c5c3c1eb81e95e2fd1f Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 13 Feb 2019 12:33:05 +0100 Subject: [PATCH 1/3] Re-check bearers when app resumes from standby --- libnymea-app-core/connection/nymeaconnection.cpp | 12 ++++++++++-- nymea-app/nymea-app.pro | 2 +- nymea-app/platformhelper.cpp | 14 ++++++++++++++ nymea-app/platformhelper.h | 2 ++ nymea-app/ui/Nymea.qml | 2 ++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/libnymea-app-core/connection/nymeaconnection.cpp b/libnymea-app-core/connection/nymeaconnection.cpp index 730cc100..a191ac52 100644 --- a/libnymea-app-core/connection/nymeaconnection.cpp +++ b/libnymea-app-core/connection/nymeaconnection.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "nymeatransportinterface.h" @@ -29,6 +30,12 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent) updateActiveBearers(); }); + QGuiApplication *app = static_cast(QGuiApplication::instance()); + QObject::connect(app, &QGuiApplication::applicationStateChanged, this, [this](Qt::ApplicationState state) { + qDebug() << "Application state changed to:" << state; + updateActiveBearers(); + }); + updateActiveBearers(); } @@ -130,7 +137,7 @@ Connection *NymeaConnection::currentConnection() const void NymeaConnection::sendData(const QByteArray &data) { if (connected()) { -// qDebug() << "sending data:" << data; + qDebug() << "sending data:" << data; m_currentTransport->sendData(data); } else { qWarning() << "Connection: Not connected. Cannot send."; @@ -328,9 +335,10 @@ void NymeaConnection::onDisconnected() t->deleteLater(); if (!m_currentTransport && m_transportCandidates.isEmpty()) { - qDebug() << "Last connection dropped. Trying to reconnect.."; + qDebug() << "Last connection dropped."; QTimer::singleShot(1000, this, [this](){ if (m_currentHost) { + qDebug() << "Trying to reconnect.."; connectInternal(m_currentHost); } }); diff --git a/nymea-app/nymea-app.pro b/nymea-app/nymea-app.pro index 67564987..b3e84269 100644 --- a/nymea-app/nymea-app.pro +++ b/nymea-app/nymea-app.pro @@ -2,7 +2,7 @@ TEMPLATE=app TARGET=nymea-app include(../config.pri) -QT += network qml quick quickcontrols2 svg websockets bluetooth charts +QT += network qml quick quickcontrols2 svg websockets bluetooth charts gui-private INCLUDEPATH += $$top_srcdir/libnymea-common \ $$top_srcdir/libnymea-app-core diff --git a/nymea-app/platformhelper.cpp b/nymea-app/platformhelper.cpp index de4fd04f..2e4f0089 100644 --- a/nymea-app/platformhelper.cpp +++ b/nymea-app/platformhelper.cpp @@ -1,8 +1,22 @@ #include "platformhelper.h" +#include PlatformHelper::PlatformHelper(QObject *parent) : QObject(parent) { } + + +QVariantMap PlatformHelper::getSafeAreaMargins(QQuickWindow *window) +{ +// QPlatformWindow *platformWindow = window->handle(); +// QMargins margins = platformWindow->safeAreaMargins(); + QVariantMap map; +// map["top"] = margins.top(); +// map["right"] = margins.right(); +// map["bottom"] = margins.bottom(); +// map["left"] = margins.left(); + return map; +} diff --git a/nymea-app/platformhelper.h b/nymea-app/platformhelper.h index d5bbbef4..0f943c5b 100644 --- a/nymea-app/platformhelper.h +++ b/nymea-app/platformhelper.h @@ -2,6 +2,7 @@ #define PLATFORMHELPER_H #include +#include class PlatformHelper : public QObject { @@ -35,6 +36,7 @@ public: Q_INVOKABLE virtual void vibrate(HapticsFeedback feedbackType) = 0; + Q_INVOKABLE QVariantMap getSafeAreaMargins(QQuickWindow *window); signals: void permissionsRequestFinished(); }; diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml index c40b307d..b1eacadd 100644 --- a/nymea-app/ui/Nymea.qml +++ b/nymea-app/ui/Nymea.qml @@ -16,6 +16,7 @@ ApplicationWindow { visibility: ApplicationWindow.AutomaticVisibility font: Qt.application.font + // Those variables must be present in the Style title: appName Material.primary: primaryColor @@ -49,6 +50,7 @@ ApplicationWindow { RootItem { id: rootItem anchors.fill: parent + anchors.topMargin: PlatformHelper.getSafeAreaMargins(app) } NymeaDiscovery { From 08b70f3bdbba2d3a3ab771b2ebbde669559ca706 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 3 Mar 2019 15:29:25 +0100 Subject: [PATCH 2/3] Fix reconnecting after connection loss --- libnymea-app-core/connection/nymeaconnection.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libnymea-app-core/connection/nymeaconnection.cpp b/libnymea-app-core/connection/nymeaconnection.cpp index a191ac52..8a89783f 100644 --- a/libnymea-app-core/connection/nymeaconnection.cpp +++ b/libnymea-app-core/connection/nymeaconnection.cpp @@ -344,6 +344,7 @@ void NymeaConnection::onDisconnected() }); } + qDebug() << "Current transport:" << m_currentTransport << "Remaining connections:" << m_transportCandidates.count() << "Current host:" << m_currentHost; return; } m_transportCandidates.remove(m_currentTransport); @@ -365,7 +366,7 @@ void NymeaConnection::onDisconnected() emit connectedChanged(false); } - if (!m_currentTransport) { + if (!m_currentHost) { return; } From 08b42b8505bcedad7ef2b2543aa5b10c23b7b013 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 4 Mar 2019 10:21:28 +0100 Subject: [PATCH 3/3] Drop accidentally committed code --- nymea-app/platformhelper.cpp | 16 ---------------- nymea-app/platformhelper.h | 2 -- 2 files changed, 18 deletions(-) diff --git a/nymea-app/platformhelper.cpp b/nymea-app/platformhelper.cpp index 2e4f0089..8e276a31 100644 --- a/nymea-app/platformhelper.cpp +++ b/nymea-app/platformhelper.cpp @@ -1,22 +1,6 @@ #include "platformhelper.h" -#include - PlatformHelper::PlatformHelper(QObject *parent) : QObject(parent) { } - - - -QVariantMap PlatformHelper::getSafeAreaMargins(QQuickWindow *window) -{ -// QPlatformWindow *platformWindow = window->handle(); -// QMargins margins = platformWindow->safeAreaMargins(); - QVariantMap map; -// map["top"] = margins.top(); -// map["right"] = margins.right(); -// map["bottom"] = margins.bottom(); -// map["left"] = margins.left(); - return map; -} diff --git a/nymea-app/platformhelper.h b/nymea-app/platformhelper.h index 0f943c5b..d5bbbef4 100644 --- a/nymea-app/platformhelper.h +++ b/nymea-app/platformhelper.h @@ -2,7 +2,6 @@ #define PLATFORMHELPER_H #include -#include class PlatformHelper : public QObject { @@ -36,7 +35,6 @@ public: Q_INVOKABLE virtual void vibrate(HapticsFeedback feedbackType) = 0; - Q_INVOKABLE QVariantMap getSafeAreaMargins(QQuickWindow *window); signals: void permissionsRequestFinished(); };