made env vars behave like the rest of the settings

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-10-26 22:51:38 +03:00
parent e9fd02baca
commit 12d567a9b8
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
6 changed files with 17 additions and 53 deletions

View File

@ -188,9 +188,8 @@ void MinecraftInstance::loadSpecificSettings()
auto legacySettings = m_settings->registerSetting("OverrideLegacySettings", false);
m_settings->registerOverride(global_settings->getSetting("OnlineFixes"), legacySettings);
m_settings->registerSetting("UseEnv", false);
m_settings->registerSetting("OverrideEnv", false);
m_settings->registerSetting("Env", QVariant(QMap<QString, QVariant>()));
auto envSetting = m_settings->registerSetting("OverrideEnv", false);
m_settings->registerOverride(global_settings->getSetting("Env"), envSetting);
m_settings->set("InstanceType", "OneSix");
}
@ -612,12 +611,11 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment()
env.insert(iter.key(), iter.value().toString());
};
bool useEnv = settings()->get("UseEnv").toBool();
bool overrideEnv = useEnv && settings()->get("OverrideEnv").toBool();
bool overrideEnv = settings()->get("OverrideEnv").toBool();
if (!overrideEnv)
insertEnv(APPLICATION->settings()->get("Env").toMap());
if (useEnv)
else
insertEnv(settings()->get("Env").toMap());
return env;

View File

@ -29,7 +29,7 @@ EnvironmentVariablesPage::EnvironmentVariablesPage(QWidget* parent) : QWidget(pa
variables->setContentsMargins(6, 6, 6, 6);
verticalLayout->addWidget(variables);
variables->initialize(false, true, false, APPLICATION->settings()->get("Env").toMap());
variables->initialize(false, false, APPLICATION->settings()->get("Env").toMap());
}
QString EnvironmentVariablesPage::displayName() const

View File

@ -203,9 +203,12 @@ void InstanceSettingsPage::applySettings()
}
// Environment Variables
m_settings->set("UseEnv", ui->environmentVariables->checked());
m_settings->set("OverrideEnv", ui->environmentVariables->override());
m_settings->set("Env", ui->environmentVariables->value());
auto env = ui->environmentVariables->override();
m_settings->set("OverrideEnv", env);
if (env)
m_settings->set("Env", ui->environmentVariables->value());
else
m_settings->reset("Env");
// Workarounds
bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked();
@ -327,8 +330,7 @@ void InstanceSettingsPage::loadSettings()
m_settings->get("WrapperCommand").toString(), m_settings->get("PostExitCommand").toString());
// Environment variables
ui->environmentVariables->initialize(true, m_settings->get("UseEnv").toBool(), m_settings->get("OverrideEnv").toBool(),
m_settings->get("Env").toMap());
ui->environmentVariables->initialize(true, m_settings->get("OverrideEnv").toBool(), m_settings->get("Env").toMap());
// Workarounds
ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool());

View File

@ -50,25 +50,6 @@ EnvironmentVariables::EnvironmentVariables(QWidget* parent) : QWidget(parent), u
});
connect(ui->clear, &QPushButton::clicked, this, [this] { ui->list->clear(); });
connect(ui->globalOverride, &QCheckBox::clicked, this, [this](bool state) {
if (!state)
return;
auto global = APPLICATION->settings()->get("Env").toMap();
if (global.isEmpty())
return;
auto response = CustomMessageBox::selectable(
this, tr("Reset"),
tr("You have chosen to ignore global settings.\n\nWould you like to clear the current variables and copy "
"the global variables over?"),
QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec();
if (response == QMessageBox::Yes)
initialize(true, checked(), override(), global);
});
}
EnvironmentVariables::~EnvironmentVariables()
@ -76,13 +57,11 @@ EnvironmentVariables::~EnvironmentVariables()
delete ui;
}
void EnvironmentVariables::initialize(bool instance, bool checked, bool override, const QMap<QString, QVariant>& value)
void EnvironmentVariables::initialize(bool instance, bool override, const QMap<QString, QVariant>& value)
{
// update widgets to settings
ui->groupBox->setCheckable(instance);
ui->groupBox->setChecked(checked);
ui->globalOverride->setVisible(instance);
ui->globalOverride->setChecked(override);
ui->groupBox->setChecked(override);
// populate
ui->list->clear();
@ -113,18 +92,11 @@ void EnvironmentVariables::retranslate()
ui->retranslateUi(this);
}
bool EnvironmentVariables::checked() const
{
if (!ui->groupBox->isCheckable())
return true;
return ui->groupBox->isChecked();
}
bool EnvironmentVariables::override() const
{
if (!ui->globalOverride->isVisible())
if (!ui->groupBox->isCheckable())
return false;
return ui->globalOverride->isChecked();
return ui->groupBox->isChecked();
}
QMap<QString, QVariant> EnvironmentVariables::value() const

View File

@ -31,11 +31,10 @@ class EnvironmentVariables : public QWidget {
public:
explicit EnvironmentVariables(QWidget* state = nullptr);
~EnvironmentVariables() override;
void initialize(bool instance, bool checked, bool override, const QMap<QString, QVariant>& value);
void initialize(bool instance, bool override, const QMap<QString, QVariant>& value);
bool eventFilter(QObject* watched, QEvent* event) override;
void retranslate();
bool checked() const;
bool override() const;
QMap<QString, QVariant> value() const;

View File

@ -35,13 +35,6 @@
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="globalOverride">
<property name="text">
<string>&amp;Ignore global settings</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="list">
<property name="alternatingRowColors">