From 68b5fdf7489b440b61ca375452b0150bd94675e9 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 15 Jul 2023 00:03:11 +0300 Subject: [PATCH] Ask user to retry if netjob fails Signed-off-by: Trial97 --- launcher/net/NetJob.cpp | 29 +++++++++++++++++++++++++++-- launcher/net/NetJob.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/launcher/net/NetJob.cpp b/launcher/net/NetJob.cpp index 3869316e3..7b5a87788 100644 --- a/launcher/net/NetJob.cpp +++ b/launcher/net/NetJob.cpp @@ -36,6 +36,8 @@ */ #include "NetJob.h" +#include "tasks/ConcurrentTask.h" +#include "ui/dialogs/CustomMessageBox.h" auto NetJob::addNetAction(NetAction::Ptr action) -> bool { @@ -52,8 +54,11 @@ void NetJob::startNext() // We're finished, check for failures and retry if we can (up to 3 times) if (!m_failed.isEmpty() && m_try < 3) { m_try += 1; - while (!m_failed.isEmpty()) - m_queue.enqueue(m_failed.take(*m_failed.keyBegin())); + while (!m_failed.isEmpty()) { + auto task = m_failed.take(*m_failed.keyBegin()); + m_done.remove(task.get()); + m_queue.enqueue(task); + } } } @@ -127,3 +132,23 @@ void NetJob::updateState() setStatus(tr("Executing %1 task(s) (%2 out of %3 are done)") .arg(QString::number(m_doing.count()), QString::number(m_done.count()), QString::number(totalSize()))); } + +void NetJob::emitFailed(QString reason) +{ + auto response = CustomMessageBox::selectable(nullptr, "Confirm retry", + "The tasks failed\n" + "Failed urls\n" + + getFailedFiles().join("\n\t") + + "\n" + "If this continues to happen please check the logs of the application" + "Do you want to retry?", + QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) + ->exec(); + + if (response == QMessageBox::Yes) { + m_try = 0; + startNext(); + return; + } + ConcurrentTask::emitFailed(reason); +} \ No newline at end of file diff --git a/launcher/net/NetJob.h b/launcher/net/NetJob.h index 764cec18b..406ddda63 100644 --- a/launcher/net/NetJob.h +++ b/launcher/net/NetJob.h @@ -68,6 +68,7 @@ class NetJob : public ConcurrentTask { public slots: // Qt can't handle auto at the start for some reason? bool abort() override; + void emitFailed(QString reason) override; protected: void updateState() override;