fix(ManagedPackPage): better UX for when network requests fail / are pending

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-11-11 17:44:16 -03:00
parent 9539230915
commit d4979974b4
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
3 changed files with 50 additions and 3 deletions

View File

@ -127,6 +127,30 @@ bool ManagedPackPage::runUpdateTask(InstanceTask* task)
return task->wasSuccessful(); return task->wasSuccessful();
} }
void ManagedPackPage::suggestVersion()
{
ui->updateButton->setText(tr("Update pack"));
ui->updateButton->setDisabled(false);
}
void ManagedPackPage::setFailState()
{
qDebug() << "Setting fail state!";
// We block signals here so that suggestVersion() doesn't get called, causing an assertion fail.
ui->versionsComboBox->blockSignals(true);
ui->versionsComboBox->clear();
ui->versionsComboBox->addItem(tr("Failed to search for available versions."), {});
ui->versionsComboBox->blockSignals(false);
ui->changelogTextBrowser->setText(tr("Failed to request changelog data for this modpack."));
ui->updateButton->setText(tr("Cannot update!"));
ui->updateButton->setDisabled(true);
// TODO: Perhaps start a timer here when m_loaded is false to try and reload.
}
ModrinthManagedPackPage::ModrinthManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent) ModrinthManagedPackPage::ModrinthManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent)
: ManagedPackPage(inst, instance_window, parent) : ManagedPackPage(inst, instance_window, parent)
{ {
@ -153,6 +177,9 @@ void ModrinthManagedPackPage::parseManagedPack()
qWarning() << "Error while parsing JSON response from Modrinth at " << parse_error.offset qWarning() << "Error while parsing JSON response from Modrinth at " << parse_error.offset
<< " reason: " << parse_error.errorString(); << " reason: " << parse_error.errorString();
qWarning() << *response; qWarning() << *response;
setFailState();
return; return;
} }
@ -161,6 +188,9 @@ void ModrinthManagedPackPage::parseManagedPack()
} catch (const JSONValidationError& e) { } catch (const JSONValidationError& e) {
qDebug() << *response; qDebug() << *response;
qWarning() << "Error while reading modrinth modpack version: " << e.cause(); qWarning() << "Error while reading modrinth modpack version: " << e.cause();
setFailState();
return;
} }
for (auto version : m_pack.versions) { for (auto version : m_pack.versions) {
@ -183,6 +213,8 @@ void ModrinthManagedPackPage::parseManagedPack()
m_loaded = true; m_loaded = true;
}); });
QObject::connect(netJob, &NetJob::failed, this, &ModrinthManagedPackPage::setFailState);
QObject::connect(netJob, &NetJob::aborted, this, &ModrinthManagedPackPage::setFailState);
QObject::connect(netJob, &NetJob::finished, this, [response, netJob] { QObject::connect(netJob, &NetJob::finished, this, [response, netJob] {
netJob->deleteLater(); netJob->deleteLater();
delete response; delete response;
@ -202,6 +234,8 @@ void ModrinthManagedPackPage::suggestVersion()
HoeDown md_parser; HoeDown md_parser;
ui->changelogTextBrowser->setHtml(md_parser.process(version.changelog.toUtf8())); ui->changelogTextBrowser->setHtml(md_parser.process(version.changelog.toUtf8()));
ManagedPackPage::suggestVersion();
} }
void ModrinthManagedPackPage::update() void ModrinthManagedPackPage::update()

View File

@ -51,12 +51,22 @@ class ManagedPackPage : public QWidget, public BasePage {
void setInstanceWindow(InstanceWindow* window) { m_instance_window = window; } void setInstanceWindow(InstanceWindow* window) { m_instance_window = window; }
public slots: public slots:
/** Gets the current version selection and update the changelog. /** Gets the current version selection and update the UI, including the update button and the changelog.
*/ */
virtual void suggestVersion() {}; virtual void suggestVersion();
virtual void update() {}; virtual void update() {};
protected slots:
/** Does the necessary UI changes for when something failed.
*
* This includes:
* - Setting an appropriate text on the version selector to indicate a fail;
* - Setting an appropriate text on the changelog text browser to indicate a fail;
* - Disable the update button.
*/
void setFailState();
protected: protected:
ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent = nullptr); ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent = nullptr);

View File

@ -133,6 +133,9 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="updateButton"> <widget class="QPushButton" name="updateButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -140,7 +143,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Update pack</string> <string>Fetching versions...</string>
</property> </property>
</widget> </widget>
</item> </item>