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

enh: show only one error when there's a network issue

parent 0d368734
No related branches found
No related tags found
1 merge request!38QDS-11878 Reduce the numbers of user notification
Pipeline #67247 passed
<?xml version="1.0"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.qt.qtdesignviewer"
android:installLocation="auto" android:versionCode="25" android:versionName="1.2">
android:installLocation="auto" android:versionCode="26" android:versionName="1.2">
<!-- %%INSERT_PERMISSIONS -->
<!-- %%INSERT_FEATURES -->
<supports-screens android:anyDensity="true" android:largeScreens="true"
......
......@@ -336,10 +336,12 @@ void Backend::runDemoProject(const QString &projectName)
// sample project info
// [{"lastUpdate":1701947766739.9812,"name":"ClusterTutorial.qmlrc"}]
const std::optional<QJsonArray> projectList = m_serviceConnector.fetchUserDemoList();
const std::optional<QJsonArray> projectList = m_serviceConnector.fetchDemoList();
if (projectList == std::nullopt) {
qCritical("Please check your internet connection and try again");
qCritical(
"Could not fetch demo project list. Please check your internet connection and try "
"again.");
emit popupClose();
return;
}
......@@ -357,9 +359,8 @@ void Backend::runDemoProject(const QString &projectName)
if (!cached) {
updatePopup("Downloading demo project...", false);
const QString url = "https://designviewer.qt.io/qmlprojects/demos/" + projectName
+ ".qmlrc";
const std::optional<QByteArray> project = m_serviceConnector.fetchProject(url);
const std::optional<QByteArray> project = m_serviceConnector.fetchDemo(projectName
+ ".qmlrc");
if (project == std::nullopt) {
qCritical() << "Could not download demo project. Please check the logs for more "
......@@ -368,8 +369,6 @@ void Backend::runDemoProject(const QString &projectName)
return;
}
qDebug() << "Demo project is not cached. Trying to download from " << url << " ...";
updatePopup("Caching demo project...");
if (!m_projectManager->cacheDemoProject(project.value(), projectInfo)) {
qCritical()
......@@ -416,7 +415,8 @@ void Backend::runUserProject(const QString &projectName)
const std::optional<QJsonArray> projectList = m_serviceConnector.fetchUserProjectList(userHash);
if (projectList == std::nullopt) {
qCritical("Please check your internet connection and try again");
qCritical("Could not fetch up-to-date project information. Please check your internet "
"connection and try again.");
emit popupClose();
return;
}
......@@ -505,8 +505,8 @@ void Backend::updateUserProjectList()
const std::optional<QJsonArray> projectList = m_serviceConnector.fetchUserProjectList(userHash);
if (projectList == std::nullopt) {
qWarning("Could not fetch project list. Either there are no projects or there is a "
"network issue");
qWarning(
"Could not fetch project list. Please check your internet connection and try again.");
} else if (projectList.value() == m_projectList) {
qDebug("No new projects are available");
} else {
......
......@@ -31,7 +31,7 @@
#include <QJsonDocument>
#include <QJsonObject>
QByteArray ServiceConnector::fetchResource(const QString &url, const bool quite)
std::optional<QByteArray> ServiceConnector::fetchResource(const QString &url)
{
qDebug() << "Fetching resource from" << url;
......@@ -42,10 +42,7 @@ QByteArray ServiceConnector::fetchResource(const QString &url, const bool quite)
&QNetworkReply::sslErrors,
this,
[&](const QList<QSslError> &errors) {
if (!quite)
qCritical() << errors.first().errorString();
else
qWarning() << errors.first().errorString();
qWarning() << errors.first().errorString();
});
QEventLoop loop;
......@@ -63,56 +60,42 @@ QByteArray ServiceConnector::fetchResource(const QString &url, const bool quite)
loop.exec();
if (reply->error() != QNetworkReply::NoError) {
if (!quite)
qCritical() << reply->errorString();
else
qWarning() << reply->errorString();
} else {
qDebug() << "Resource fetched successfully";
qWarning() << reply->errorString();
return {};
}
qDebug() << "Resource fetched successfully";
return reply->readAll();
}
std::optional<QByteArray> ServiceConnector::fetchProject(const QString &url)
{
QString projectUrl = url;
if (projectUrl.startsWith("https://designviewer.qt.io/#"))
{
if (projectUrl.startsWith(m_serviceUrl + "/#")) {
projectUrl = projectUrl.split("#").at(1);
projectUrl.prepend("https://designviewer.qt.io/qmlprojects/");
projectUrl.prepend(m_serviceUrl + "/qmlprojects/");
}
auto reply = fetchResource(projectUrl);
if (reply.size() == 0)
return {};
return reply;
return fetchResource(projectUrl);
}
std::optional<QByteArray> ServiceConnector::fetchUserProject(const QString &userHash,
const QString &projectName)
{
const QString projectUrl = "https://designviewer.qt.io/qmlprojects/" + userHash + "/"
+ projectName + ".qmlrc";
auto reply = fetchResource(projectUrl);
if (reply.size() == 0)
return {};
const QString projectUrl = m_serviceUrl + "/qmlprojects/" + userHash + "/" + projectName
+ ".qmlrc";
return reply;
return fetchResource(projectUrl);
}
std::optional<QJsonArray> ServiceConnector::fetchUserProjectList(const QString &userHash)
{
auto reply = fetchResource("https://designviewer.qt.io/api/v1/qmlrc/list/" + userHash
+ "?key=818815",
true);
auto reply = fetchResource(m_serviceUrl + "/api/v1/qmlrc/list/" + userHash + "?key=818815");
if (reply.size() == 0)
if (!reply)
return {};
QJsonArray projectList = QJsonDocument::fromJson(reply)
QJsonArray projectList = QJsonDocument::fromJson(reply.value())
.object()
.value("data")
.toObject()
......@@ -122,11 +105,16 @@ std::optional<QJsonArray> ServiceConnector::fetchUserProjectList(const QString &
return projectList;
}
std::optional<QJsonArray> ServiceConnector::fetchUserDemoList()
std::optional<QJsonArray> ServiceConnector::fetchDemoList()
{
auto reply = fetchResource("https://designviewer.qt.io/api/v1/demos");
if (reply.size() == 0)
auto reply = fetchResource(m_serviceUrl + "/api/v1/demos");
if (!reply)
return {};
return QJsonDocument::fromJson(reply).array();
return QJsonDocument::fromJson(reply.value()).array();
}
std::optional<QByteArray> ServiceConnector::fetchDemo(const QString &demoName)
{
return fetchResource(m_serviceUrl + "/qmlprojects/demos/" + demoName + ".qmlrc");
}
......@@ -36,11 +36,14 @@ public:
std::optional<QByteArray> fetchProject(const QString &url);
std::optional<QByteArray> fetchUserProject(const QString &userHash, const QString &projectName);
std::optional<QJsonArray> fetchUserProjectList(const QString &userHash);
std::optional<QJsonArray> fetchUserDemoList();
std::optional<QJsonArray> fetchDemoList();
std::optional<QByteArray> fetchDemo(const QString &demoName);
private:
QNetworkAccessManager m_manager;
QByteArray fetchResource(const QString &url, const bool quite = false);
std::optional<QByteArray> fetchResource(const QString &url);
const QString m_serviceUrl = "https://designviewer.qt.io";
signals:
void downloadProgress(float percentage);
......
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