fix(ManagedPackPage): better UX for when network requests fail / are pending
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
9539230915
commit
d4979974b4
@ -127,6 +127,30 @@ bool ManagedPackPage::runUpdateTask(InstanceTask* task)
|
||||
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)
|
||||
: ManagedPackPage(inst, instance_window, parent)
|
||||
{
|
||||
@ -153,6 +177,9 @@ void ModrinthManagedPackPage::parseManagedPack()
|
||||
qWarning() << "Error while parsing JSON response from Modrinth at " << parse_error.offset
|
||||
<< " reason: " << parse_error.errorString();
|
||||
qWarning() << *response;
|
||||
|
||||
setFailState();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -161,6 +188,9 @@ void ModrinthManagedPackPage::parseManagedPack()
|
||||
} catch (const JSONValidationError& e) {
|
||||
qDebug() << *response;
|
||||
qWarning() << "Error while reading modrinth modpack version: " << e.cause();
|
||||
|
||||
setFailState();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto version : m_pack.versions) {
|
||||
@ -183,6 +213,8 @@ void ModrinthManagedPackPage::parseManagedPack()
|
||||
|
||||
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] {
|
||||
netJob->deleteLater();
|
||||
delete response;
|
||||
@ -202,6 +234,8 @@ void ModrinthManagedPackPage::suggestVersion()
|
||||
|
||||
HoeDown md_parser;
|
||||
ui->changelogTextBrowser->setHtml(md_parser.process(version.changelog.toUtf8()));
|
||||
|
||||
ManagedPackPage::suggestVersion();
|
||||
}
|
||||
|
||||
void ModrinthManagedPackPage::update()
|
||||
|
@ -51,12 +51,22 @@ class ManagedPackPage : public QWidget, public BasePage {
|
||||
void setInstanceWindow(InstanceWindow* window) { m_instance_window = window; }
|
||||
|
||||
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() {};
|
||||
|
||||
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:
|
||||
ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent = nullptr);
|
||||
|
||||
|
@ -133,6 +133,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="updateButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@ -140,7 +143,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Update pack</string>
|
||||
<string>Fetching versions...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user