Merge pull request #1350 from Trial97/fix_managed_pack_crash

fixed crash if no version is loaded on managed page
This commit is contained in:
Rachel Powers 2023-07-12 09:55:31 -07:00 committed by Sefa Eyeoglu
parent a0ddd85b32
commit b11b86e026
No known key found for this signature in database
GPG Key ID: E13DFD4B47127951

View File

@ -69,7 +69,6 @@ class NoBigComboBoxStyle : public QProxyStyle {
private: private:
NoBigComboBoxStyle(QStyle* style) : QProxyStyle(style) {} NoBigComboBoxStyle(QStyle* style) : QProxyStyle(style) {}
}; };
ManagedPackPage* ManagedPackPage::createPage(BaseInstance* inst, QString type, QWidget* parent) ManagedPackPage* ManagedPackPage::createPage(BaseInstance* inst, QString type, QWidget* parent)
@ -91,13 +90,13 @@ ManagedPackPage::ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_wi
// NOTE: GTK2 themes crash with the proxy style. // NOTE: GTK2 themes crash with the proxy style.
// This seems like an upstream bug, so there's not much else that can be done. // This seems like an upstream bug, so there's not much else that can be done.
if (!QStyleFactory::keys().contains("gtk2")){ if (!QStyleFactory::keys().contains("gtk2")) {
auto comboStyle = NoBigComboBoxStyle::getInstance(ui->versionsComboBox->style()); auto comboStyle = NoBigComboBoxStyle::getInstance(ui->versionsComboBox->style());
ui->versionsComboBox->setStyle(comboStyle); ui->versionsComboBox->setStyle(comboStyle);
} }
ui->reloadButton->setVisible(false); ui->reloadButton->setVisible(false);
connect(ui->reloadButton, &QPushButton::clicked, this, [this](bool){ connect(ui->reloadButton, &QPushButton::clicked, this, [this](bool) {
ui->reloadButton->setVisible(false); ui->reloadButton->setVisible(false);
m_loaded = false; m_loaded = false;
@ -226,7 +225,8 @@ void ModrinthManagedPackPage::parseManagedPack()
QString id = m_inst->getManagedPackID(); QString id = m_inst->getManagedPackID();
m_fetch_job->addNetAction(Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response)); m_fetch_job->addNetAction(
Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(m_fetch_job.get(), &NetJob::succeeded, this, [this, response, id] { QObject::connect(m_fetch_job.get(), &NetJob::succeeded, this, [this, response, id] {
QJsonParseError parse_error{}; QJsonParseError parse_error{};
@ -267,7 +267,6 @@ void ModrinthManagedPackPage::parseManagedPack()
if (version.version == m_inst->getManagedPackVersionName()) if (version.version == m_inst->getManagedPackVersionName())
name = tr("%1 (Current)").arg(name); name = tr("%1 (Current)").arg(name);
ui->versionsComboBox->addItem(name, QVariant(version.id)); ui->versionsComboBox->addItem(name, QVariant(version.id));
} }
@ -291,6 +290,10 @@ QString ModrinthManagedPackPage::url() const
void ModrinthManagedPackPage::suggestVersion() void ModrinthManagedPackPage::suggestVersion()
{ {
auto index = ui->versionsComboBox->currentIndex(); auto index = ui->versionsComboBox->currentIndex();
if (m_pack.versions.length() == 0) {
setFailState();
return;
}
auto version = m_pack.versions.at(index); auto version = m_pack.versions.at(index);
ui->changelogTextBrowser->setHtml(markdownToHTML(version.changelog.toUtf8())); ui->changelogTextBrowser->setHtml(markdownToHTML(version.changelog.toUtf8()));
@ -301,6 +304,10 @@ void ModrinthManagedPackPage::suggestVersion()
void ModrinthManagedPackPage::update() void ModrinthManagedPackPage::update()
{ {
auto index = ui->versionsComboBox->currentIndex(); auto index = ui->versionsComboBox->currentIndex();
if (m_pack.versions.length() == 0) {
setFailState();
return;
}
auto version = m_pack.versions.at(index); auto version = m_pack.versions.at(index);
QMap<QString, QString> extra_info; QMap<QString, QString> extra_info;
@ -429,6 +436,10 @@ QString FlameManagedPackPage::url() const
void FlameManagedPackPage::suggestVersion() void FlameManagedPackPage::suggestVersion()
{ {
auto index = ui->versionsComboBox->currentIndex(); auto index = ui->versionsComboBox->currentIndex();
if (m_pack.versions.length() == 0) {
setFailState();
return;
}
auto version = m_pack.versions.at(index); auto version = m_pack.versions.at(index);
ui->changelogTextBrowser->setHtml(m_api.getModFileChangelog(m_inst->getManagedPackID().toInt(), version.fileId)); ui->changelogTextBrowser->setHtml(m_api.getModFileChangelog(m_inst->getManagedPackID().toInt(), version.fileId));
@ -439,6 +450,10 @@ void FlameManagedPackPage::suggestVersion()
void FlameManagedPackPage::update() void FlameManagedPackPage::update()
{ {
auto index = ui->versionsComboBox->currentIndex(); auto index = ui->versionsComboBox->currentIndex();
if (m_pack.versions.length() == 0) {
setFailState();
return;
}
auto version = m_pack.versions.at(index); auto version = m_pack.versions.at(index);
QMap<QString, QString> extra_info; QMap<QString, QString> extra_info;