aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-05-29 21:18:34 +0200
committerSefa Eyeoglu <contact@scrumplex.net>2022-07-08 16:25:03 +0200
commit4103948132636fcb01daa866f107259a821419dd (patch)
tree03a4c9a4da41018829c2744f799829b390a69f3b /launcher
parent906f26698b73f3868939d3f66e6e639ac2da2263 (diff)
downloadPrismLauncher-4103948132636fcb01daa866f107259a821419dd.tar.gz
PrismLauncher-4103948132636fcb01daa866f107259a821419dd.tar.bz2
PrismLauncher-4103948132636fcb01daa866f107259a821419dd.zip
feat: track capabilities of application
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Application.cpp10
-rw-r--r--launcher/Application.h10
-rw-r--r--launcher/net/Download.cpp3
-rw-r--r--launcher/net/Upload.cpp3
-rw-r--r--launcher/ui/dialogs/ModDownloadDialog.cpp15
-rw-r--r--launcher/ui/dialogs/ModDownloadDialog.h3
-rw-r--r--launcher/ui/dialogs/NewInstanceDialog.cpp27
-rw-r--r--launcher/ui/dialogs/NewInstanceDialog.h1
-rw-r--r--launcher/ui/pages/global/AccountListPage.cpp2
9 files changed, 47 insertions, 27 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index ee27adea..099b49f1 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -1569,6 +1569,16 @@ shared_qobject_ptr<Meta::Index> Application::metadataIndex()
return m_metadataIndex;
}
+Application::Capabilities Application::currentCapabilities()
+{
+ Capabilities c;
+ if (!getMSAClientID().isEmpty())
+ c |= SupportsMSA;
+ if (!getFlameAPIKey().isEmpty())
+ c |= SupportsFlame;
+ return c;
+}
+
QString Application::getJarPath(QString jarFile)
{
QStringList potentialPaths = {
diff --git a/launcher/Application.h b/launcher/Application.h
index 5eb2f832..3113f552 100644
--- a/launcher/Application.h
+++ b/launcher/Application.h
@@ -93,6 +93,14 @@ public:
Initialized
};
+ enum Capability {
+ None = 0,
+
+ SupportsMSA = 1 << 0,
+ SupportsFlame = 1 << 1,
+ };
+ Q_DECLARE_FLAGS(Capabilities, Capability)
+
public:
Application(int &argc, char **argv);
virtual ~Application();
@@ -157,6 +165,8 @@ public:
shared_qobject_ptr<Meta::Index> metadataIndex();
+ Capabilities currentCapabilities();
+
/*!
* Finds and returns the full path to a jar file.
* Returns a null-string if it could not be found.
diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp
index 0557f2e3..e73f662f 100644
--- a/launcher/net/Download.cpp
+++ b/launcher/net/Download.cpp
@@ -117,7 +117,8 @@ void Download::executeTask()
}
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
- if (request.url().host().contains("api.curseforge.com")) {
+ if (APPLICATION->currentCapabilities() & Application::SupportsFlame
+ && request.url().host().contains("api.curseforge.com")) {
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
};
diff --git a/launcher/net/Upload.cpp b/launcher/net/Upload.cpp
index 2173bd08..496120b4 100644
--- a/launcher/net/Upload.cpp
+++ b/launcher/net/Upload.cpp
@@ -174,7 +174,8 @@ namespace Net {
}
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
- if (request.url().host().contains("api.curseforge.com")) {
+ if (APPLICATION->currentCapabilities() & Application::SupportsFlame
+ && request.url().host().contains("api.curseforge.com")) {
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
}
//TODO other types of post requests ?
diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp
index f01c9c07..86c55eff 100644
--- a/launcher/ui/dialogs/ModDownloadDialog.cpp
+++ b/launcher/ui/dialogs/ModDownloadDialog.cpp
@@ -4,6 +4,7 @@
#include <icons/IconList.h>
#include <InstanceList.h>
+#include "Application.h"
#include "ProgressDialog.h"
#include "ReviewMessageBox.h"
@@ -100,13 +101,13 @@ void ModDownloadDialog::accept()
QList<BasePage *> ModDownloadDialog::getPages()
{
- modrinthPage = new ModrinthModPage(this, m_instance);
- flameModPage = new FlameModPage(this, m_instance);
- return
- {
- modrinthPage,
- flameModPage
- };
+ QList<BasePage *> pages;
+
+ pages.append(new ModrinthModPage(this, m_instance));
+ if (APPLICATION->currentCapabilities() & Application::SupportsFlame)
+ pages.append(new FlameModPage(this, m_instance));
+
+ return pages;
}
void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* task)
diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h
index 5c565ad3..f863725f 100644
--- a/launcher/ui/dialogs/ModDownloadDialog.h
+++ b/launcher/ui/dialogs/ModDownloadDialog.h
@@ -48,9 +48,6 @@ private:
QDialogButtonBox * m_buttons = nullptr;
QVBoxLayout *m_verticalLayout = nullptr;
-
- ModrinthModPage *modrinthPage = nullptr;
- FlameModPage *flameModPage = nullptr;
QHash<QString, ModDownloadTask*> modTask;
BaseInstance *m_instance;
};
diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp
index 05ea091d..7e0e0692 100644
--- a/launcher/ui/dialogs/NewInstanceDialog.cpp
+++ b/launcher/ui/dialogs/NewInstanceDialog.cpp
@@ -124,20 +124,21 @@ void NewInstanceDialog::accept()
QList<BasePage *> NewInstanceDialog::getPages()
{
+ QList<BasePage *> pages;
+
importPage = new ImportPage(this);
- flamePage = new FlamePage(this);
- auto technicPage = new TechnicPage(this);
- return
- {
- new VanillaPage(this),
- importPage,
- new AtlPage(this),
- flamePage,
- new FtbPage(this),
- new LegacyFTB::Page(this),
- new ModrinthPage(this),
- technicPage
- };
+
+ pages.append(new VanillaPage(this));
+ pages.append(importPage);
+ pages.append(new AtlPage(this));
+ if (APPLICATION->currentCapabilities() & Application::SupportsFlame)
+ pages.append(new FlamePage(this));
+ pages.append(new FtbPage(this));
+ pages.append(new LegacyFTB::Page(this));
+ pages.append(new ModrinthPage(this));
+ pages.append(new TechnicPage(this));
+
+ return pages;
}
QString NewInstanceDialog::dialogTitle()
diff --git a/launcher/ui/dialogs/NewInstanceDialog.h b/launcher/ui/dialogs/NewInstanceDialog.h
index ef74634e..9b86ca4f 100644
--- a/launcher/ui/dialogs/NewInstanceDialog.h
+++ b/launcher/ui/dialogs/NewInstanceDialog.h
@@ -69,7 +69,6 @@ private:
QString InstIconKey;
ImportPage *importPage = nullptr;
- FlamePage *flamePage = nullptr;
std::unique_ptr<InstanceTask> creationTask;
bool importIcon = false;
diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp
index a608771e..b7216883 100644
--- a/launcher/ui/pages/global/AccountListPage.cpp
+++ b/launcher/ui/pages/global/AccountListPage.cpp
@@ -96,7 +96,7 @@ AccountListPage::AccountListPage(QWidget *parent)
updateButtonStates();
// Xbox authentication won't work without a client identifier, so disable the button if it is missing
- if (APPLICATION->getMSAClientID().isEmpty()) {
+ if (APPLICATION->currentCapabilities() & Application::SupportsMSA) {
ui->actionAddMicrosoft->setVisible(false);
ui->actionAddMicrosoft->setToolTip(tr("No Microsoft Authentication client ID was set."));
}