diff --git a/3rdparty/qtquickdesigner-components b/3rdparty/qtquickdesigner-components index 34b97d40d86d7c243cb6bf8245d717397ef25268..04a5f670d3e7ae28e54bf194a3dd70e13d05ffc4 160000 --- a/3rdparty/qtquickdesigner-components +++ b/3rdparty/qtquickdesigner-components @@ -1 +1 @@ -Subproject commit 34b97d40d86d7c243cb6bf8245d717397ef25268 +Subproject commit 04a5f670d3e7ae28e54bf194a3dd70e13d05ffc4 diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index 17c297622ecfc9c9f2ff45a7f09295d93de47843..5a7be45d196e9311bb0dab9de544e211400fbcf4 100644 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -26,9 +26,12 @@ #include "backend.h" #include <QDesktopServices> -#include <QJniObject> #include <QNetworkInterface> +#ifdef Q_OS_ANDROID +#include <QJniObject> +#endif + #include "logger.h" #ifdef QT_DEBUG @@ -266,12 +269,16 @@ void Backend::setKeepScreenOn(bool keepScreenOn) void Backend::setAndroidScreenOn(bool on) { +#ifdef Q_OS_ANDROID QNativeInterface::QAndroidApplication::runOnAndroidMainThread([=]() { QJniObject activity = QNativeInterface::QAndroidApplication::context(); QJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;"); on ? window.callMethod<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON) : window.callMethod<void>("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON); }); +#else + Q_UNUSED(on); +#endif } QString Backend::lastDesignStudioIp() const diff --git a/src/backend/dsconnector/ds.cpp b/src/backend/dsconnector/ds.cpp index b6817517b7c42558f0e982522c2a648452adfb79..6275546472ae2753a745c80a24241d4505bdc59f 100644 --- a/src/backend/dsconnector/ds.cpp +++ b/src/backend/dsconnector/ds.cpp @@ -21,7 +21,7 @@ DesignStudio::DesignStudio(QWebSocket *socket, const QString &m_deviceUuid, QObj void DesignStudio::initPingPong() { m_pingTimer.setInterval(1000); - m_pongTimer.setInterval(10000); + m_pongTimer.setInterval(30000); m_pongTimer.setSingleShot(true); m_pingTimer.setSingleShot(true); diff --git a/src/backend/projectmanager.cpp b/src/backend/projectmanager.cpp index 6f2bcb13fafd1ace258dcb6094d818efc605d417..acb50e386421c4e086a6b1292c9b145012bd8ca4 100644 --- a/src/backend/projectmanager.cpp +++ b/src/backend/projectmanager.cpp @@ -32,6 +32,7 @@ #include <QRandomGenerator> #include <QRegularExpression> #include <QResource> +#include <QStandardPaths> #include <QTemporaryDir> ProjectManager::ProjectManager(QObject *parent) @@ -40,45 +41,98 @@ ProjectManager::ProjectManager(QObject *parent) ProjectManager::~ProjectManager() { - qDebug() << "ProjectManager destroyed. Cleaning up resources."; - cleanupResources(); + unregisterResource(m_projectData, m_projectPath); } -void ProjectManager::cleanupResources() +bool ProjectManager::unregisterResource(const QByteArray &data, const QString &path) { - const uchar *data; - if (m_projectData.size()) { - qDebug() << "Unregistering the previous data from QRC system. Path: " << m_projectPath - << " Size: " << m_projectData.size() << " bytes."; - data = reinterpret_cast<const uchar *>(m_projectData.data()); - if (!QResource::unregisterResource(data, m_projectPath)) { + const uchar *charPtr; + if (data.size()) { + qDebug() << "Unregistering the previous data from QRC system. Path: " << path + << " Size: " << data.size() << " bytes."; + charPtr = reinterpret_cast<const uchar *>(data.data()); + if (!QResource::unregisterResource(charPtr, path)) { qCritical() << "Cannot unregister the previous resource data."; + return false; } } + + return true; } -QString ProjectManager::unpackProject(const QByteArray &project) +bool ProjectManager::registerResource(const QByteArray &data, const QString &path) { - cleanupResources(); + if (!QDir(path).removeRecursively()) { + qWarning() << "Could not remove resource path: " << path; + return false; + } - m_projectData = project; - const uchar *data; - data = reinterpret_cast<const uchar *>(m_projectData.data()); - qDebug() << "Registering resource data. Size: " << m_projectData.size(); + qDebug() << "Registering resource data. Size: " << data.size(); + const uchar *resourceData = reinterpret_cast<const uchar *>(data.data()); + if (!QResource::registerResource(resourceData, path)) { + qCritical() << "Cannot register the resource data."; + return false; + } - const QString resourcePath{"/" + QString::number(QRandomGenerator::global()->generate())}; - m_projectPath = resourcePath; + return true; +} - if (!QDir(resourcePath).removeRecursively()) { - qWarning() << "Could not remove resource path: " << resourcePath; +bool ProjectManager::copyResourceToFs(const QString &sourcePath, const QString &destPath) +{ + QDir tmpDir(destPath); + if (tmpDir.exists()) { + if (!tmpDir.removeRecursively()) { + qCritical() << "Could not remove tmp dir: " << destPath; + return false; + } } - if (!QResource::registerResource(data, resourcePath)) { - qCritical() << "Can not load the resource data."; + if (!tmpDir.mkpath(destPath)) { + qCritical() << "Could not create tmp dir: " << destPath; + return false; + } + + QDirIterator it(sourcePath, + QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, + QDirIterator::Subdirectories); + + while (it.hasNext()) { + it.next(); + const QString filePath = it.filePath(); + const QString relativePath = it.filePath().mid(sourcePath.length()); + const QString targetPath = destPath + relativePath; + + qDebug() << "Copying file: " << filePath << " to " << targetPath; + if (it.fileInfo().isDir()) { + QDir().mkpath(targetPath); + } else { + QFile file(filePath); + if (!file.copy(targetPath)) { + qCritical() << "Could not copy file: " << filePath << " to " << targetPath; + return false; + } + } + } + + return true; +} + +QString ProjectManager::unpackProject(const QByteArray &project) +{ + if (!unregisterResource(m_projectData, m_projectPath)) { + qCritical() << "Could not unregister previous resource: " << m_projectPath; return {}; } - return QString(":") + resourcePath; + const QString resourcePath{":/" + QString::number(QRandomGenerator::global()->generate())}; + if (!registerResource(project, resourcePath)) { + qCritical() << "Could not register resource: " << resourcePath; + return {}; + } + m_projectData = project; + m_projectPath = resourcePath; + + return resourcePath; } QString ProjectManager::findFile(const QString &dir, const QString &filter) diff --git a/src/backend/projectmanager.h b/src/backend/projectmanager.h index cde6e9575289197c9f3eb745e579d7b9734c923c..5240f857f0e5b066c1fe623811015f7930c93d27 100644 --- a/src/backend/projectmanager.h +++ b/src/backend/projectmanager.h @@ -52,7 +52,9 @@ private: QScopedPointer<QQuickWindow> m_quickWindow; // resource management - void cleanupResources(); + bool registerResource(const QByteArray &data, const QString &path); + bool unregisterResource(const QByteArray &data, const QString &path); + bool copyResourceToFs(const QString &sourcePath, const QString &targetPath); QString unpackProject(const QByteArray &project); // project parsers