Skip to content
Snippets Groups Projects
Verified Commit d011f122 authored by Burak Hançerli's avatar Burak Hançerli :headphones:
Browse files

fix: increase the ping timer interval to be able to wait for larger projects

parent 430df3a3
No related branches found
Tags v2.0.0-b3
No related merge requests found
Pipeline #77958 passed
Subproject commit 34b97d40d86d7c243cb6bf8245d717397ef25268
Subproject commit 04a5f670d3e7ae28e54bf194a3dd70e13d05ffc4
......@@ -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
......
......@@ -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);
......
......@@ -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)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment