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 <lenny@sneed.church>
This commit is contained in:
Lenny McLennington 2022-10-27 01:42:32 +01:00
parent e7853533b4
commit 5229cb8c12
No known key found for this signature in database
GPG Key ID: F0467078ECA45FCB
3 changed files with 32 additions and 26 deletions

View File

@ -953,32 +953,6 @@ void Application::performMainStartupAction()
{ {
m_status = Application::Initialized; 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()) if(!m_instanceIdToLaunch.isEmpty())
{ {
auto inst = instances()->getInstanceById(m_instanceIdToLaunch); auto inst = instances()->getInstanceById(m_instanceIdToLaunch);
@ -1008,6 +982,32 @@ void Application::performMainStartupAction()
return; 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) if(!m_mainWindow)
{ {
// normal main window // normal main window

View File

@ -52,6 +52,9 @@
QString GuiUtil::fetchFlameKey(QWidget *parentWidget) QString GuiUtil::fetchFlameKey(QWidget *parentWidget)
{ {
if (BuildConfig.FLAME_API_KEY_API_URL.isEmpty())
return "";
ProgressDialog prog(parentWidget); ProgressDialog prog(parentWidget);
auto flameKeyTask = std::make_unique<FetchFlameAPIKey>(); auto flameKeyTask = std::make_unique<FetchFlameAPIKey>();
prog.execWithTask(flameKeyTask.get()); prog.execWithTask(flameKeyTask.get());

View File

@ -89,6 +89,9 @@ APIPage::APIPage(QWidget *parent) :
ui->metaURL->setPlaceholderText(BuildConfig.META_URL); ui->metaURL->setPlaceholderText(BuildConfig.META_URL);
ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT); ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT);
if (BuildConfig.FLAME_API_KEY_API_URL.isEmpty())
ui->fetchKeyButton->hide();
loadSettings(); loadSettings();
resetBaseURLNote(); resetBaseURLNote();