From 2a8c91ce60d28a6990fb07001b1a28ced2223b6c Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 3 Feb 2022 23:01:13 +0100 Subject: [PATCH] Fix a crash when syncing remote connection configs via a remote connection --- .../configuration/serverconfiguration.cpp | 4 ++++ libnymea-app/configuration/serverconfiguration.h | 1 + libnymea-app/connection/nymeahost.cpp | 15 --------------- libnymea-app/connection/nymeahost.h | 2 -- nymea-app/ui/RootItem.qml | 7 +++++++ 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/libnymea-app/configuration/serverconfiguration.cpp b/libnymea-app/configuration/serverconfiguration.cpp index a12c2199..eaef633e 100644 --- a/libnymea-app/configuration/serverconfiguration.cpp +++ b/libnymea-app/configuration/serverconfiguration.cpp @@ -41,6 +41,10 @@ ServerConfiguration::ServerConfiguration(const QString &id, const QString &addre } +ServerConfiguration::~ServerConfiguration() +{ +} + QString ServerConfiguration::id() const { return m_id; diff --git a/libnymea-app/configuration/serverconfiguration.h b/libnymea-app/configuration/serverconfiguration.h index 3ea194df..ae1a0e0e 100644 --- a/libnymea-app/configuration/serverconfiguration.h +++ b/libnymea-app/configuration/serverconfiguration.h @@ -46,6 +46,7 @@ class ServerConfiguration : public QObject public: explicit ServerConfiguration(const QString &id, const QString &address = QString(), int port = 0, bool authEnabled = false, bool sslEnabled = false, QObject *parent = nullptr); + virtual ~ServerConfiguration(); QString id() const; diff --git a/libnymea-app/connection/nymeahost.cpp b/libnymea-app/connection/nymeahost.cpp index d0b90a8d..50cbc95e 100644 --- a/libnymea-app/connection/nymeahost.cpp +++ b/libnymea-app/connection/nymeahost.cpp @@ -101,21 +101,6 @@ bool NymeaHost::online() const return m_online; } -void NymeaHost::addTunnelConnection() -{ - for (int i = 0; i < m_connections->rowCount(); i++) { - if (m_connections->get(i)->url().scheme() == "tunnel") { - return; - } - } - QUrl url; - url.setScheme("tunnel"); - url.setHost(m_uuid.toString().remove(QRegExp("[{}]"))); - qCritical() << "Adding tunnel connection" << url << m_uuid; - Connection *connection = new Connection(url, Connection::BearerTypeCloud, true, "foooobaaaar", this); - m_connections->addConnection(connection); -} - void NymeaHost::syncOnlineState() { for (int i = 0; i < m_connections->rowCount(); i++) { diff --git a/libnymea-app/connection/nymeahost.h b/libnymea-app/connection/nymeahost.h index b1f25d9e..c07bc772 100644 --- a/libnymea-app/connection/nymeahost.h +++ b/libnymea-app/connection/nymeahost.h @@ -158,8 +158,6 @@ public: bool online() const; - Q_INVOKABLE void addTunnelConnection(); - signals: void nameChanged(); void versionChanged(); diff --git a/nymea-app/ui/RootItem.qml b/nymea-app/ui/RootItem.qml index 22aca65d..67e82ba5 100644 --- a/nymea-app/ui/RootItem.qml +++ b/nymea-app/ui/RootItem.qml @@ -352,6 +352,13 @@ Item { } function syncRemoteConnection() { + if (engine.jsonRpcClient.currentConnection.url.toString().startsWith("tunnel")) { + // Not resyncing tunnel configurations while we're connected through a tunnel ourselves + // (We could, maybe even should, but currently libnymea-app borrows the "NymeaHost" pointer from + // the hostsmodel and will crash if we delete the used Connection object) + return; + } + for (var i = 0; i < engine.jsonRpcClient.currentHost.connections.count; i++) { var connection = engine.jsonRpcClient.currentHost.connections.get(i) if (connection.url.toString().startsWith("tunnel")) {