Automatically install authlib-injector when missing
Add MissingAuthlibInjectorBehavior setting to control this behavior Signed-off-by: Evan Goode <mail@evangoo.de>
This commit is contained in:
parent
ca5574130f
commit
aa589701ed
@ -115,6 +115,7 @@
|
|||||||
#include "tools/MCEditTool.h"
|
#include "tools/MCEditTool.h"
|
||||||
|
|
||||||
#include "settings/INISettingsObject.h"
|
#include "settings/INISettingsObject.h"
|
||||||
|
#include "settings/MissingAuthlibInjectorBehavior.h"
|
||||||
#include "settings/Setting.h"
|
#include "settings/Setting.h"
|
||||||
|
|
||||||
#include "meta/Index.h"
|
#include "meta/Index.h"
|
||||||
@ -601,6 +602,9 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
|||||||
// Minecraft mods
|
// Minecraft mods
|
||||||
m_settings->registerSetting("ModMetadataDisabled", false);
|
m_settings->registerSetting("ModMetadataDisabled", false);
|
||||||
|
|
||||||
|
// Missing authlib-injector behavior
|
||||||
|
m_settings->registerSetting("MissingAuthlibInjectorBehavior", MissingAuthlibInjectorBehavior::Ask);
|
||||||
|
|
||||||
// Minecraft offline player name
|
// Minecraft offline player name
|
||||||
m_settings->registerSetting("LastOfflinePlayerName", "");
|
m_settings->registerSetting("LastOfflinePlayerName", "");
|
||||||
|
|
||||||
@ -982,12 +986,10 @@ void Application::performMainStartupAction()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
bool shouldFetch = m_settings->get("FlameKeyShouldBeFetchedOnStartup").toBool();
|
bool shouldFetch = m_settings->get("FlameKeyShouldBeFetchedOnStartup").toBool();
|
||||||
if (!BuildConfig.FLAME_API_KEY_API_URL.isEmpty() && shouldFetch && !(capabilities() & Capability::SupportsFlame))
|
if (!BuildConfig.FLAME_API_KEY_API_URL.isEmpty() && shouldFetch && !(capabilities() & Capability::SupportsFlame)) {
|
||||||
{
|
|
||||||
// don't ask, just fetch
|
// don't ask, just fetch
|
||||||
QString apiKey = GuiUtil::fetchFlameKey();
|
QString apiKey = GuiUtil::fetchFlameKey();
|
||||||
if (!apiKey.isEmpty())
|
if (!apiKey.isEmpty()) {
|
||||||
{
|
|
||||||
m_settings->set("FlameKeyOverride", apiKey);
|
m_settings->set("FlameKeyOverride", apiKey);
|
||||||
updateCapabilities();
|
updateCapabilities();
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,6 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
|
|||||||
m_settings->registerSetting("ManagedPackVersionName", "");
|
m_settings->registerSetting("ManagedPackVersionName", "");
|
||||||
|
|
||||||
m_settings->registerSetting("Profiler", "");
|
m_settings->registerSetting("Profiler", "");
|
||||||
|
|
||||||
m_settings->registerSetting("SuggestAuthlibInjector", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::getPreLaunchCommand()
|
QString BaseInstance::getPreLaunchCommand()
|
||||||
|
@ -430,6 +430,7 @@ set(SETTINGS_SOURCES
|
|||||||
settings/Setting.h
|
settings/Setting.h
|
||||||
settings/SettingsObject.cpp
|
settings/SettingsObject.cpp
|
||||||
settings/SettingsObject.h
|
settings/SettingsObject.h
|
||||||
|
settings/MissingAuthlibInjectorBehavior.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(JAVA_SOURCES
|
set(JAVA_SOURCES
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "LaunchController.h"
|
#include "LaunchController.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "minecraft/auth/AccountList.h"
|
#include "minecraft/auth/AccountList.h"
|
||||||
|
#include "settings/MissingAuthlibInjectorBehavior.h"
|
||||||
#include "ui/pages/instance/VersionPage.h"
|
#include "ui/pages/instance/VersionPage.h"
|
||||||
|
|
||||||
#include "ui/InstanceWindow.h"
|
#include "ui/InstanceWindow.h"
|
||||||
@ -59,6 +60,8 @@
|
|||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
#include "JavaCommon.h"
|
#include "JavaCommon.h"
|
||||||
#include "launch/steps/TextPrint.h"
|
#include "launch/steps/TextPrint.h"
|
||||||
|
#include "meta/Index.h"
|
||||||
|
#include "meta/VersionList.h"
|
||||||
#include "minecraft/auth/AccountTask.h"
|
#include "minecraft/auth/AccountTask.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
@ -143,44 +146,85 @@ void LaunchController::login()
|
|||||||
|
|
||||||
if (m_accountToUse->usesCustomApiServers()) {
|
if (m_accountToUse->usesCustomApiServers()) {
|
||||||
MinecraftInstancePtr inst = std::dynamic_pointer_cast<MinecraftInstance>(m_instance);
|
MinecraftInstancePtr inst = std::dynamic_pointer_cast<MinecraftInstance>(m_instance);
|
||||||
const auto suggestAuthlibInjector = m_instance->settings()->get("SuggestAuthlibInjector").toBool();
|
|
||||||
const auto& authlibInjectorVersion = inst->getPackProfile()->getComponentVersion("moe.yushi.authlibinjector");
|
const auto& authlibInjectorVersion = inst->getPackProfile()->getComponentVersion("moe.yushi.authlibinjector");
|
||||||
if (suggestAuthlibInjector && authlibInjectorVersion == "") {
|
|
||||||
|
if (authlibInjectorVersion == "") {
|
||||||
// Account uses custom API servers, but authlib-injector is missing
|
// Account uses custom API servers, but authlib-injector is missing
|
||||||
// Prompt user to install authlib-injector on the instance before launching
|
|
||||||
QMessageBox msgBox{ m_parentWidget };
|
|
||||||
msgBox.setWindowTitle(tr("Missing authlib-injector"));
|
|
||||||
msgBox.setText(tr("authlib-injector is not installed."));
|
|
||||||
msgBox.setInformativeText(
|
|
||||||
tr("You are logging in using an account that uses custom API servers, but authlib-injector "
|
|
||||||
"is not installed on this instance.\n\n"
|
|
||||||
"Would you like to install authlib-injector now?"));
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ignore | QMessageBox::Yes);
|
|
||||||
msgBox.setDefaultButton(QMessageBox::Yes);
|
|
||||||
msgBox.setModal(true);
|
|
||||||
|
|
||||||
QCheckBox* checkBox = new QCheckBox("Don't ask again", m_parentWidget);
|
int globalMissingBehavior = APPLICATION->settings()->get("MissingAuthlibInjectorBehavior").toInt();
|
||||||
checkBox->setChecked(!suggestAuthlibInjector);
|
int missingBehavior = globalMissingBehavior;
|
||||||
|
|
||||||
msgBox.setCheckBox(checkBox);
|
if (globalMissingBehavior == MissingAuthlibInjectorBehavior::Ask) {
|
||||||
const auto& result = msgBox.exec();
|
QMessageBox msgBox{ m_parentWidget };
|
||||||
|
msgBox.setWindowTitle(tr("Missing authlib-injector"));
|
||||||
|
msgBox.setText(tr("authlib-injector is not installed."));
|
||||||
|
msgBox.setInformativeText(
|
||||||
|
tr("You are logging in using an account that uses custom API servers, but authlib-injector "
|
||||||
|
"is not installed on this instance.\n\n"
|
||||||
|
"Would you like to install authlib-injector now?"));
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ignore | QMessageBox::Yes);
|
||||||
|
msgBox.setDefaultButton(QMessageBox::Yes);
|
||||||
|
msgBox.setModal(true);
|
||||||
|
|
||||||
m_instance->settings()->set("SuggestAuthlibInjector", !checkBox->isChecked());
|
QCheckBox* checkBox = new QCheckBox("Always do the same for all instances without asking", m_parentWidget);
|
||||||
|
checkBox->setChecked(false);
|
||||||
|
|
||||||
switch (result) {
|
msgBox.setCheckBox(checkBox);
|
||||||
case QMessageBox::Ignore:
|
const auto& result = msgBox.exec();
|
||||||
break;
|
|
||||||
case QMessageBox::Cancel:
|
switch (result) {
|
||||||
return;
|
case QMessageBox::Cancel: {
|
||||||
case QMessageBox::Yes:
|
return;
|
||||||
if (result == QMessageBox::Yes) {
|
} break;
|
||||||
const auto& window = APPLICATION->showInstanceWindow(m_instance, "version");
|
case QMessageBox::Ignore: {
|
||||||
const auto& page = dynamic_cast<VersionPage*>(window->getPage("version"));
|
missingBehavior = MissingAuthlibInjectorBehavior::Ignore;
|
||||||
if (page != nullptr) {
|
} break;
|
||||||
page->openInstallAuthlibInjector();
|
case QMessageBox::Yes: {
|
||||||
}
|
missingBehavior = MissingAuthlibInjectorBehavior::Install;
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkBox->isChecked()) {
|
||||||
|
globalMissingBehavior = missingBehavior;
|
||||||
|
APPLICATION->settings()->set("MissingAuthlibInjectorBehavior", globalMissingBehavior);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
missingBehavior = globalMissingBehavior;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (missingBehavior == MissingAuthlibInjectorBehavior::Install) {
|
||||||
|
// Install recommended authlib-injector version
|
||||||
|
try {
|
||||||
|
auto vlist = APPLICATION->metadataIndex()->get("moe.yushi.authlibinjector");
|
||||||
|
if (!vlist) {
|
||||||
|
throw Exception(tr("No authlib-injector versions available."));
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressDialog loadDialog(m_parentWidget);
|
||||||
|
loadDialog.setSkipButton(true, tr("Abort"));
|
||||||
|
auto loadTask = vlist->getLoadTask();
|
||||||
|
loadDialog.execWithTask(loadTask.get());
|
||||||
|
|
||||||
|
if (!loadTask->wasSuccessful()) {
|
||||||
|
throw Exception(tr("Failed to load authlib-injector versions."));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto recommended = vlist->getRecommended();
|
||||||
|
if (recommended == nullptr) {
|
||||||
|
throw Exception(tr("No authlib-injector versions available."));
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->getPackProfile()->setComponentVersion("moe.yushi.authlibinjector", recommended->descriptor());
|
||||||
|
} catch (const Exception& e) {
|
||||||
|
const auto& message = e.cause() + "\n\n" + tr("Launch anyway?");
|
||||||
|
auto result = QMessageBox::question(m_parentWidget, tr("Failed to install authlib-injector"), message);
|
||||||
|
|
||||||
|
if (result == QMessageBox::No) {
|
||||||
|
emitAborted();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
#include <Version.h>
|
#include <Version.h>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
7
launcher/settings/MissingAuthlibInjectorBehavior.h
Normal file
7
launcher/settings/MissingAuthlibInjectorBehavior.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum MissingAuthlibInjectorBehavior {
|
||||||
|
Ask,
|
||||||
|
Ignore,
|
||||||
|
Install,
|
||||||
|
};
|
@ -48,6 +48,7 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
#include "DesktopServices.h"
|
#include "DesktopServices.h"
|
||||||
|
#include "settings/MissingAuthlibInjectorBehavior.h"
|
||||||
#include "settings/SettingsObject.h"
|
#include "settings/SettingsObject.h"
|
||||||
#include "ui/themes/ITheme.h"
|
#include "ui/themes/ITheme.h"
|
||||||
#include "updater/ExternalUpdater.h"
|
#include "updater/ExternalUpdater.h"
|
||||||
@ -76,6 +77,11 @@ LauncherPage::LauncherPage(QWidget* parent) : QWidget(parent), ui(new Ui::Launch
|
|||||||
defaultFormat = new QTextCharFormat(ui->fontPreview->currentCharFormat());
|
defaultFormat = new QTextCharFormat(ui->fontPreview->currentCharFormat());
|
||||||
|
|
||||||
m_languageModel = APPLICATION->translations();
|
m_languageModel = APPLICATION->translations();
|
||||||
|
|
||||||
|
ui->missingAIComboBox->addItem("Always ask", MissingAuthlibInjectorBehavior::Ask);
|
||||||
|
ui->missingAIComboBox->addItem("Ignore missing authlib-injector", MissingAuthlibInjectorBehavior::Ignore);
|
||||||
|
ui->missingAIComboBox->addItem("Automatically install authlib-injector", MissingAuthlibInjectorBehavior::Install);
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
ui->updateSettingsBox->setHidden(!APPLICATION->updater());
|
ui->updateSettingsBox->setHidden(!APPLICATION->updater());
|
||||||
@ -220,6 +226,9 @@ void LauncherPage::applySettings()
|
|||||||
|
|
||||||
// Mods
|
// Mods
|
||||||
s->set("ModMetadataDisabled", ui->metadataDisableBtn->isChecked());
|
s->set("ModMetadataDisabled", ui->metadataDisableBtn->isChecked());
|
||||||
|
|
||||||
|
// authlib-injector
|
||||||
|
s->set("MissingAuthlibInjectorBehavior", ui->missingAIComboBox->currentData().toInt());
|
||||||
}
|
}
|
||||||
void LauncherPage::loadSettings()
|
void LauncherPage::loadSettings()
|
||||||
{
|
{
|
||||||
@ -272,6 +281,14 @@ void LauncherPage::loadSettings()
|
|||||||
// Mods
|
// Mods
|
||||||
ui->metadataDisableBtn->setChecked(s->get("ModMetadataDisabled").toBool());
|
ui->metadataDisableBtn->setChecked(s->get("ModMetadataDisabled").toBool());
|
||||||
ui->metadataWarningLabel->setHidden(!ui->metadataDisableBtn->isChecked());
|
ui->metadataWarningLabel->setHidden(!ui->metadataDisableBtn->isChecked());
|
||||||
|
|
||||||
|
// Missing authlib-injector behavior
|
||||||
|
int missingAI = s->get("MissingAuthlibInjectorBehavior").toInt();
|
||||||
|
int missingAIIndex = ui->missingAIComboBox->findData(missingAI);
|
||||||
|
if (missingAIIndex == -1) {
|
||||||
|
missingAIIndex = ui->missingAIComboBox->findData(MissingAuthlibInjectorBehavior::Ask);
|
||||||
|
}
|
||||||
|
ui->missingAIComboBox->setCurrentIndex(missingAIIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherPage::refreshFontPreview()
|
void LauncherPage::refreshFontPreview()
|
||||||
|
@ -189,6 +189,22 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="authlibInjectorBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Missing authlib-injector behavior</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="missingAIComboBox">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>What to do when using an authlib-injector account with an instance that does not have authlib-injector installed</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer_2">
|
<spacer name="verticalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -262,8 +262,6 @@ void InstanceSettingsPage::applySettings()
|
|||||||
m_settings->reset("DisableQuiltBeacon");
|
m_settings->reset("DisableQuiltBeacon");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_settings->set("SuggestAuthlibInjector", ui->suggestAuthlibInjector->isChecked());
|
|
||||||
|
|
||||||
// FIXME: This should probably be called by a signal instead
|
// FIXME: This should probably be called by a signal instead
|
||||||
m_instance->updateRuntimeContext();
|
m_instance->updateRuntimeContext();
|
||||||
}
|
}
|
||||||
@ -371,8 +369,6 @@ void InstanceSettingsPage::loadSettings()
|
|||||||
// Mod loader specific settings
|
// Mod loader specific settings
|
||||||
ui->modLoaderSettingsGroupBox->setChecked(m_settings->get("OverrideModLoaderSettings").toBool());
|
ui->modLoaderSettingsGroupBox->setChecked(m_settings->get("OverrideModLoaderSettings").toBool());
|
||||||
ui->disableQuiltBeaconCheckBox->setChecked(m_settings->get("DisableQuiltBeacon").toBool());
|
ui->disableQuiltBeaconCheckBox->setChecked(m_settings->get("DisableQuiltBeacon").toBool());
|
||||||
|
|
||||||
ui->suggestAuthlibInjector->setChecked(m_settings->get("SuggestAuthlibInjector").toBool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
||||||
|
@ -710,16 +710,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="suggestAuthlibInjector">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string><html><head/><body><p>Suggest installing authlib-injector when using custom API servers.</p></body></html></string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Suggest Authlib Injector</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacerMiscellaneous">
|
<spacer name="verticalSpacerMiscellaneous">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
Loading…
Reference in New Issue
Block a user