Skip to content

Commit

Permalink
Merge pull request PrismLauncher#2440 from Trial97/fix_retry_dialog
Browse files Browse the repository at this point in the history
update retry netjob dialog
  • Loading branch information
Trial97 authored Jul 19, 2024
2 parents 69c55d9 + 4b4da8e commit 0041d2a
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)

m_settings->registerSetting("NumberOfConcurrentTasks", 10);
m_settings->registerSetting("NumberOfConcurrentDownloads", 6);
m_settings->registerSetting("NumberOfManualRetries", 1);
m_settings->registerSetting("RequestTimeout", 60);

QString defaultMonospace;
Expand Down
1 change: 1 addition & 0 deletions launcher/modplatform/flame/FileResolvingTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void Flame::FileResolvingTask::netJobFinished()
setProgress(1, 3);
// job to check modrinth for blocked projects
m_checkJob.reset(new NetJob("Modrinth check", m_network));
m_checkJob->setAskRetry(false);
blockedProjects = QMap<File*, std::shared_ptr<QByteArray>>();

QJsonDocument doc;
Expand Down
1 change: 0 additions & 1 deletion launcher/net/ApiDownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ auto ApiDownload::makeFile(QUrl url, QString path, Options options) -> Download:

void ApiDownload::init()
{
qDebug() << "Setting up api download";
auto api_headers = new ApiHeaderProxy();
addHeaderProxy(api_headers);
}
Expand Down
1 change: 0 additions & 1 deletion launcher/net/ApiUpload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Upload::Ptr ApiUpload::makeByteArray(QUrl url, std::shared_ptr<QByteArray> outpu

void ApiUpload::init()
{
qDebug() << "Setting up api upload";
auto api_headers = new ApiHeaderProxy();
addHeaderProxy(api_headers);
}
Expand Down
16 changes: 15 additions & 1 deletion launcher/net/NetJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/

#include "NetJob.h"
#include <QNetworkReply>
#include "net/NetRequest.h"
#include "tasks/ConcurrentTask.h"
#if defined(LAUNCHER_APPLICATION)
Expand Down Expand Up @@ -145,10 +146,23 @@ void NetJob::updateState()
.arg(QString::number(m_doing.count()), QString::number(m_done.count()), QString::number(totalSize())));
}

bool NetJob::isOnline()
{
// check some errors that are ussually associated with the lack of internet
for (auto job : getFailedActions()) {
auto err = job->error();
if (err != QNetworkReply::HostNotFoundError && err != QNetworkReply::NetworkSessionFailedError) {
return true;
}
}
return false;
};

void NetJob::emitFailed(QString reason)
{
#if defined(LAUNCHER_APPLICATION)
if (m_ask_retry) {
if (m_ask_retry && m_manual_try < APPLICATION->settings()->get("NumberOfManualRetries").toInt() && isOnline()) {
m_manual_try++;
auto response = CustomMessageBox::selectable(nullptr, "Confirm retry",
"The tasks failed.\n"
"Failed urls\n" +
Expand Down
2 changes: 2 additions & 0 deletions launcher/net/NetJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ class NetJob : public ConcurrentTask {

protected:
void updateState() override;
bool isOnline();

private:
shared_qobject_ptr<QNetworkAccessManager> m_network;

int m_try = 1;
bool m_ask_retry = true;
int m_manual_try = 0;
};
1 change: 1 addition & 0 deletions launcher/news/NewsChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void NewsChecker::reloadNews()

NetJob::Ptr job{ new NetJob("News RSS Feed", m_network) };
job->addNetAction(Net::Download::makeByteArray(m_feedUrl, newsData));
job->setAskRetry(false);
QObject::connect(job.get(), &NetJob::succeeded, this, &NewsChecker::rssDownloadFinished);
QObject::connect(job.get(), &NetJob::failed, this, &NewsChecker::rssDownloadFailed);
m_newsNetJob.reset(job);
Expand Down
1 change: 1 addition & 0 deletions launcher/translations/TranslationsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ void TranslationsModel::downloadIndex()
auto task = Net::Download::makeCached(QUrl(BuildConfig.TRANSLATIONS_BASE_URL + "index_v2.json"), entry);
d->m_index_task = task.get();
d->m_index_job->addNetAction(task);
d->m_index_job->setAskRetry(false);
connect(d->m_index_job.get(), &NetJob::failed, this, &TranslationsModel::indexFailed);
connect(d->m_index_job.get(), &NetJob::succeeded, this, &TranslationsModel::indexReceived);
d->m_index_job->start();
Expand Down
2 changes: 2 additions & 0 deletions launcher/ui/pages/global/LauncherPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ void LauncherPage::applySettings()

s->set("NumberOfConcurrentTasks", ui->numberOfConcurrentTasksSpinBox->value());
s->set("NumberOfConcurrentDownloads", ui->numberOfConcurrentDownloadsSpinBox->value());
s->set("NumberOfManualRetries", ui->numberOfManualRetriesSpinBox->value());
s->set("RequestTimeout", ui->timeoutSecondsSpinBox->value());

// Console settings
Expand Down Expand Up @@ -261,6 +262,7 @@ void LauncherPage::loadSettings()

ui->numberOfConcurrentTasksSpinBox->setValue(s->get("NumberOfConcurrentTasks").toInt());
ui->numberOfConcurrentDownloadsSpinBox->setValue(s->get("NumberOfConcurrentDownloads").toInt());
ui->numberOfManualRetriesSpinBox->setValue(s->get("NumberOfManualRetries").toInt());
ui->timeoutSecondsSpinBox->setValue(s->get("RequestTimeout").toInt());

// Console settings
Expand Down
14 changes: 14 additions & 0 deletions launcher/ui/pages/global/LauncherPage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,20 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="numberOfManualRetriesLabel">
<property name="text">
<string>Number of manual retries</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="numberOfManualRetriesSpinBox">
<property name="minimum">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
4 changes: 3 additions & 1 deletion launcher/ui/pages/modplatform/ResourceModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
if (QPixmapCache::find(url.toString(), &pixmap))
return { pixmap };

if (!m_current_icon_job)
if (!m_current_icon_job) {
m_current_icon_job.reset(new NetJob("IconJob", APPLICATION->network()));
m_current_icon_job->setAskRetry(false);
}

if (m_currently_running_icon_actions.contains(url))
return {};
Expand Down
1 change: 1 addition & 0 deletions launcher/ui/pages/modplatform/atlauncher/AtlListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ void ListModel::requestLogo(QString file, QString url)

MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file));
auto job = new NetJob(QString("ATLauncher Icon Download %1").arg(file), APPLICATION->network());
job->setAskRetry(false);
job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));

auto fullPath = entry->getFullPath();
Expand Down
1 change: 1 addition & 0 deletions launcher/ui/pages/modplatform/flame/FlameModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void ListModel::requestLogo(QString logo, QString url)

MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo));
auto job = new NetJob(QString("Flame Icon Download %1").arg(logo), APPLICATION->network());
job->setAskRetry(false);
job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));

auto fullPath = entry->getFullPath();
Expand Down
1 change: 1 addition & 0 deletions launcher/ui/pages/modplatform/legacy_ftb/ListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ void ListModel::requestLogo(QString file)

MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file));
NetJob* job = new NetJob(QString("FTB Icon Download for %1").arg(file), APPLICATION->network());
job->setAskRetry(false);
job->addNetAction(Net::ApiDownload::makeCached(QUrl(QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));

auto fullPath = entry->getFullPath();
Expand Down
1 change: 1 addition & 0 deletions launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ void ModpackListModel::requestLogo(QString logo, QString url)

MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry(m_parent->metaEntryBase(), QString("logos/%1").arg(logo));
auto job = new NetJob(QString("%1 Icon Download %2").arg(m_parent->debugName()).arg(logo), APPLICATION->network());
job->setAskRetry(false);
job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));

auto fullPath = entry->getFullPath();
Expand Down
1 change: 1 addition & 0 deletions launcher/ui/pages/modplatform/technic/TechnicModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ void Technic::ListModel::requestLogo(QString logo, QString url)

MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("TechnicPacks", QString("logos/%1").arg(logo));
auto job = new NetJob(QString("Technic Icon Download %1").arg(logo), APPLICATION->network());
job->setAskRetry(false);
job->addNetAction(Net::ApiDownload::makeCached(QUrl(url), entry));

auto fullPath = entry->getFullPath();
Expand Down
3 changes: 2 additions & 1 deletion launcher/ui/widgets/VariableSizedImageObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void VariableSizedImageObject::drawObject(QPainter* painter,
{
if (!format.hasProperty(ImageData)) {
QUrl image_url{ qvariant_cast<QString>(format.property(QTextFormat::ImageName)) };
if (m_fetching_images.contains(image_url))
if (m_fetching_images.contains(image_url) || image_url.isEmpty())
return;

auto meta = std::make_shared<ImageMetadata>();
Expand Down Expand Up @@ -140,6 +140,7 @@ void VariableSizedImageObject::loadImage(QTextDocument* doc, std::shared_ptr<Ima
QString("images/%1").arg(QString(QCryptographicHash::hash(meta->url.toEncoded(), QCryptographicHash::Algorithm::Sha1).toHex())));

auto job = new NetJob(QString("Load Image: %1").arg(meta->url.fileName()), APPLICATION->network());
job->setAskRetry(false);
job->addNetAction(Net::ApiDownload::makeCached(meta->url, entry));

auto full_entry_path = entry->getFullPath();
Expand Down

0 comments on commit 0041d2a

Please sign in to comment.