refactor: store current capabilities

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-08-08 20:49:49 +02:00
parent 75f92de8f8
commit f873cd5b1a
No known key found for this signature in database
GPG Key ID: C10411294912A422
7 changed files with 17 additions and 11 deletions

View File

@ -919,6 +919,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
{ {
return; return;
} }
updateCapabilities();
performMainStartupAction(); performMainStartupAction();
} }
@ -1564,14 +1566,13 @@ shared_qobject_ptr<Meta::Index> Application::metadataIndex()
return m_metadataIndex; return m_metadataIndex;
} }
Application::Capabilities Application::currentCapabilities() void Application::updateCapabilities()
{ {
Capabilities c; m_capabilities = None;
if (!getMSAClientID().isEmpty()) if (!getMSAClientID().isEmpty())
c |= SupportsMSA; m_capabilities |= SupportsMSA;
if (!getFlameAPIKey().isEmpty()) if (!getFlameAPIKey().isEmpty())
c |= SupportsFlame; m_capabilities |= SupportsFlame;
return c;
} }
QString Application::getJarPath(QString jarFile) QString Application::getJarPath(QString jarFile)

View File

@ -162,7 +162,7 @@ public:
shared_qobject_ptr<Meta::Index> metadataIndex(); shared_qobject_ptr<Meta::Index> metadataIndex();
Capabilities currentCapabilities(); void updateCapabilities();
/*! /*!
* Finds and returns the full path to a jar file. * Finds and returns the full path to a jar file.
@ -180,6 +180,10 @@ public:
return m_rootPath; return m_rootPath;
} }
const Capabilities capabilities() {
return m_capabilities;
}
/*! /*!
* Opens a json file using either a system default editor, or, if not empty, the editor * Opens a json file using either a system default editor, or, if not empty, the editor
* specified in the settings * specified in the settings
@ -258,6 +262,7 @@ private:
QString m_rootPath; QString m_rootPath;
Status m_status = Application::StartingUp; Status m_status = Application::StartingUp;
Capabilities m_capabilities;
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
Qt::ApplicationState m_prevAppState = Qt::ApplicationInactive; Qt::ApplicationState m_prevAppState = Qt::ApplicationInactive;

View File

@ -118,7 +118,7 @@ void Download::executeTask()
} }
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8()); request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
if (APPLICATION->currentCapabilities() & Application::SupportsFlame if (APPLICATION->capabilities() & Application::SupportsFlame
&& request.url().host().contains("api.curseforge.com")) { && request.url().host().contains("api.curseforge.com")) {
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
}; };

View File

@ -216,7 +216,7 @@ namespace Net {
} }
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8()); request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
if (APPLICATION->currentCapabilities() & Application::SupportsFlame if (APPLICATION->capabilities() & Application::SupportsFlame
&& request.url().host().contains("api.curseforge.com")) { && request.url().host().contains("api.curseforge.com")) {
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
} }

View File

@ -122,7 +122,7 @@ QList<BasePage *> ModDownloadDialog::getPages()
QList<BasePage *> pages; QList<BasePage *> pages;
pages.append(new ModrinthModPage(this, m_instance)); pages.append(new ModrinthModPage(this, m_instance));
if (APPLICATION->currentCapabilities() & Application::SupportsFlame) if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(new FlameModPage(this, m_instance)); pages.append(new FlameModPage(this, m_instance));
return pages; return pages;

View File

@ -157,7 +157,7 @@ QList<BasePage *> NewInstanceDialog::getPages()
pages.append(new VanillaPage(this)); pages.append(new VanillaPage(this));
pages.append(importPage); pages.append(importPage);
pages.append(new AtlPage(this)); pages.append(new AtlPage(this));
if (APPLICATION->currentCapabilities() & Application::SupportsFlame) if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(new FlamePage(this)); pages.append(new FlamePage(this));
pages.append(new FtbPage(this)); pages.append(new FtbPage(this));
pages.append(new LegacyFTB::Page(this)); pages.append(new LegacyFTB::Page(this));

View File

@ -96,7 +96,7 @@ AccountListPage::AccountListPage(QWidget *parent)
updateButtonStates(); updateButtonStates();
// Xbox authentication won't work without a client identifier, so disable the button if it is missing // Xbox authentication won't work without a client identifier, so disable the button if it is missing
if (~APPLICATION->currentCapabilities() & Application::SupportsMSA) { if (~APPLICATION->capabilities() & Application::SupportsMSA) {
ui->actionAddMicrosoft->setVisible(false); ui->actionAddMicrosoft->setVisible(false);
ui->actionAddMicrosoft->setToolTip(tr("No Microsoft Authentication client ID was set.")); ui->actionAddMicrosoft->setToolTip(tr("No Microsoft Authentication client ID was set."));
} }