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

QDS-12001 Downloads can be safely interrupted now

parent 678bd375
No related branches found
No related tags found
1 merge request!42QDS-12001 Downloads can be safely interrupted now
Pipeline #68116 passed
......@@ -170,37 +170,43 @@ void Backend::initDesignStudioConnector()
updatePopup("Receiving project...");
});
connect(m_designStudioConnector.data(),
&DesignStudioConnector::projectReceived,
this,
[this](const QByteArray &projectData) {
qDebug() << "Project received from Design Studio";
initializeProjectManager();
emit popupOpen();
updatePopup("Unpacking project...");
qDebug() << "Project data size: " << projectData.size();
const QString projectPath = m_projectManager->unpackProject(projectData);
if (projectPath.isEmpty()) {
qCritical() << "Could not unpack project. Please check the logs for more "
"information.";
emit popupClose();
return;
}
qDebug() << "Project unpacked to " << projectPath;
updatePopup("Running project...");
if (!m_projectManager->runProject(projectPath)) {
qCritical() << "Could not run project. Please check the logs for more "
"information.";
} else {
m_projectManager->showAppWindow();
}
connect(
m_designStudioConnector.data(),
&DesignStudioConnector::projectReceived,
this,
[this](const QByteArray &projectData) {
qDebug() << "Project received from Design Studio";
initializeProjectManager();
emit popupOpen();
updatePopup("Unpacking project...");
qDebug() << "Project data size: " << projectData.size();
const QString projectPath = m_projectManager->unpackProject(projectData);
if (projectPath.isEmpty()) {
qCritical() << "Could not unpack project. Please check the logs for more "
"information.";
emit popupClose();
m_designStudioConnector->sendProjectReceived();
});
return;
}
qDebug() << "Project unpacked to " << projectPath;
updatePopup("Running project...");
qDebug() << "Project received confirmation sent to Design Studio";
if (!m_projectManager->runProject(projectPath)) {
qCritical() << "Could not run project. Please check the logs for more "
"information.";
} else {
m_projectManager->showAppWindow();
}
QMetaObject::invokeMethod(m_designStudioConnector.data(),
"sendProjectReceived",
Qt::QueuedConnection);
emit popupClose();
},
Qt::QueuedConnection);
qDebug() << "Design Studio Connector is initialized";
}
......@@ -429,3 +435,9 @@ void Backend::parseDesignViewerUrl(const QUrl &url)
qWarning() << "Unknown QR code data: " << urlData;
}
}
void Backend::popupInterrupted()
{
qDebug() << "Popup closed prematurely. Interrupting active downloads (if any)";
QMetaObject::invokeMethod(&m_serviceConnector, "interrupted", Qt::QueuedConnection);
}
......@@ -56,7 +56,6 @@ private:
QJsonArray m_projectList;
// Other members
ServiceConnector m_serviceConnector;
QThread m_dsConnectorThread;
QScopedPointer<ProjectManager> m_projectManager;
......@@ -114,6 +113,8 @@ public slots:
bool autoScaleProject();
QString userHash();
void popupInterrupted();
private slots:
void initializeProjectManager();
void enableBackgroundUpdate(const bool &enabled);
......
......@@ -121,5 +121,5 @@ void DesignStudioConnector::sendProjectReceived()
}
m_tcpSocket->write("::qmlrc-received::");
m_tcpSocket->flush();
m_tcpSocket->waitForBytesWritten(3000);
}
......@@ -38,6 +38,7 @@ class DesignStudioConnector : public QObject
public:
explicit DesignStudioConnector(QObject *parent = nullptr);
public slots:
void sendProjectReceived();
private:
......
......@@ -46,6 +46,11 @@ std::optional<QByteArray> ServiceConnector::fetchResource(const QString &url, co
});
QEventLoop loop;
QObject::connect(this, &ServiceConnector::interrupted, reply.data(), [&]() {
qDebug() << "Aborting network request";
reply->abort();
loop.quit();
});
QObject::connect(reply.data(), &QNetworkReply::finished, &loop, &QEventLoop::quit);
QObject::connect(reply.data(),
&QNetworkReply::downloadProgress,
......
......@@ -49,6 +49,7 @@ private:
signals:
void downloadProgress(float percentage);
void interrupted();
};
#endif // SERVICECONNECTOR_H
......@@ -35,6 +35,7 @@ Rectangle {
}
Popup {
property var popupCloseReceived : false
id: popup
anchors.centerIn: parent
width: 300
......@@ -43,6 +44,12 @@ Rectangle {
focus: true
closePolicy: Popup.CloseOnEscape
onClosed: {
if (!popupCloseReceived) {
backend.popupInterrupted();
}
}
ColumnLayout {
anchors.fill: parent
Text {
......@@ -62,8 +69,10 @@ Rectangle {
target: backend
function onPopupOpen() {
popup.open()
popup.popupCloseReceived = false
}
function onPopupClose() {
popup.popupCloseReceived = true
popup.close()
}
function onPopupTextChanged(text) {
......
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