From 5229cb8c1230d4b23c6d0b10c69921821056d63e Mon Sep 17 00:00:00 2001 From: Lenny McLennington Date: Thu, 27 Oct 2022 01:42:32 +0100 Subject: [PATCH] feat: add ability to disable cf api key fetching by setting the cf api key api url to a blank string Signed-off-by: Lenny McLennington --- launcher/Application.cpp | 52 ++++++++++++++-------------- launcher/ui/GuiUtil.cpp | 3 ++ launcher/ui/pages/global/APIPage.cpp | 3 ++ 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 161c6f59..e5d5436d 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -953,32 +953,6 @@ void Application::performMainStartupAction() { m_status = Application::Initialized; - { - bool shouldFetch = m_settings->get("FlameKeyShouldBeFetchedOnStartup").toBool(); - if (shouldFetch && !(capabilities() & Capability::SupportsFlame)) - { - auto response = QMessageBox::question(nullptr, - tr("Curseforge Core API Key"), - tr("Should PolyMC try to fetch the Official Curseforge Launcher's API Key? " - "Using this key technically breaks Curseforge's Terms of Service, but this distribution of PolyMC " - "does not come with a Curseforge API key by default, so without this key or another valid API key, " - "which you can always change in the settings, you won't be able to download Curseforge modpacks."), - QMessageBox::Yes | QMessageBox::No); - - if (response == QMessageBox::Yes) - { - QString apiKey = GuiUtil::fetchFlameKey(); - if (!apiKey.isEmpty()) - { - m_settings->set("FlameKeyOverride", apiKey); - updateCapabilities(); - } - } - - m_settings->set("FlameKeyShouldBeFetchedOnStartup", false); - } - } - if(!m_instanceIdToLaunch.isEmpty()) { auto inst = instances()->getInstanceById(m_instanceIdToLaunch); @@ -1008,6 +982,32 @@ void Application::performMainStartupAction() return; } } + + { + bool shouldFetch = m_settings->get("FlameKeyShouldBeFetchedOnStartup").toBool(); + if (!BuildConfig.FLAME_API_KEY_API_URL.isEmpty() && shouldFetch && !(capabilities() & Capability::SupportsFlame)) + { + auto response = QMessageBox::question(nullptr, + tr("Curseforge Core API Key"), + tr("Should PolyMC try to fetch the Official Curseforge Launcher's API Key? " + "Using this key technically breaks Curseforge's Terms of Service, but this distribution of PolyMC " + "does not come with a Curseforge API key by default, so without this key or another valid API key, " + "which you can always change in the settings, you won't be able to download Curseforge modpacks."), + QMessageBox::Yes | QMessageBox::No); + + if (response == QMessageBox::Yes) + { + QString apiKey = GuiUtil::fetchFlameKey(); + if (!apiKey.isEmpty()) + { + m_settings->set("FlameKeyOverride", apiKey); + updateCapabilities(); + } + } + } + m_settings->set("FlameKeyShouldBeFetchedOnStartup", false); + } + if(!m_mainWindow) { // normal main window diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index 2395b799..1ea989e1 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -52,6 +52,9 @@ QString GuiUtil::fetchFlameKey(QWidget *parentWidget) { + if (BuildConfig.FLAME_API_KEY_API_URL.isEmpty()) + return ""; + ProgressDialog prog(parentWidget); auto flameKeyTask = std::make_unique(); prog.execWithTask(flameKeyTask.get()); diff --git a/launcher/ui/pages/global/APIPage.cpp b/launcher/ui/pages/global/APIPage.cpp index 6cfd2f9b..6ee352c0 100644 --- a/launcher/ui/pages/global/APIPage.cpp +++ b/launcher/ui/pages/global/APIPage.cpp @@ -89,6 +89,9 @@ APIPage::APIPage(QWidget *parent) : ui->metaURL->setPlaceholderText(BuildConfig.META_URL); ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT); + if (BuildConfig.FLAME_API_KEY_API_URL.isEmpty()) + ui->fetchKeyButton->hide(); + loadSettings(); resetBaseURLNote();