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

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