Merge pull request #1355 from TheKodeToad/env-vars
Custom environment variables
This commit is contained in:
71
launcher/ui/pages/global/EnvironmentVariablesPage.cpp
Normal file
71
launcher/ui/pages/global/EnvironmentVariablesPage.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QTabBar>
|
||||
#include <QTabWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "EnvironmentVariablesPage.h"
|
||||
|
||||
EnvironmentVariablesPage::EnvironmentVariablesPage(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
auto verticalLayout = new QVBoxLayout(this);
|
||||
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
|
||||
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
auto tabWidget = new QTabWidget(this);
|
||||
tabWidget->setObjectName(QStringLiteral("tabWidget"));
|
||||
variables = new EnvironmentVariables(this);
|
||||
variables->setContentsMargins(6, 6, 6, 6);
|
||||
tabWidget->addTab(variables, "Foo");
|
||||
tabWidget->tabBar()->hide();
|
||||
verticalLayout->addWidget(tabWidget);
|
||||
|
||||
variables->initialize(false, false, APPLICATION->settings()->get("Env").toMap());
|
||||
}
|
||||
|
||||
QString EnvironmentVariablesPage::displayName() const
|
||||
{
|
||||
return tr("Environment Variables");
|
||||
}
|
||||
|
||||
QIcon EnvironmentVariablesPage::icon() const
|
||||
{
|
||||
return APPLICATION->getThemedIcon("environment-variables");
|
||||
}
|
||||
|
||||
QString EnvironmentVariablesPage::id() const
|
||||
{
|
||||
return "environment-variables";
|
||||
}
|
||||
|
||||
QString EnvironmentVariablesPage::helpPage() const
|
||||
{
|
||||
return "Environment-variables";
|
||||
}
|
||||
|
||||
bool EnvironmentVariablesPage::apply()
|
||||
{
|
||||
APPLICATION->settings()->set("Env", variables->value());
|
||||
return true;
|
||||
}
|
||||
|
||||
void EnvironmentVariablesPage::retranslate()
|
||||
{
|
||||
variables->retranslate();
|
||||
}
|
42
launcher/ui/pages/global/EnvironmentVariablesPage.h
Normal file
42
launcher/ui/pages/global/EnvironmentVariablesPage.h
Normal file
@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include "ui/widgets/EnvironmentVariables.h"
|
||||
|
||||
class EnvironmentVariablesPage : public QWidget, public BasePage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EnvironmentVariablesPage(QWidget* parent = nullptr);
|
||||
|
||||
QString displayName() const override;
|
||||
QIcon icon() const override;
|
||||
QString id() const override;
|
||||
QString helpPage() const override;
|
||||
|
||||
bool apply() override;
|
||||
void retranslate() override;
|
||||
|
||||
private:
|
||||
EnvironmentVariables* variables;
|
||||
};
|
@ -90,6 +90,9 @@ void InstanceSettingsPage::globalSettingsButtonClicked(bool)
|
||||
case 2:
|
||||
APPLICATION->ShowGlobalSettings(this, "custom-commands");
|
||||
return;
|
||||
case 3:
|
||||
APPLICATION->ShowGlobalSettings(this, "environment-variables");
|
||||
return;
|
||||
default:
|
||||
APPLICATION->ShowGlobalSettings(this, "minecraft-settings");
|
||||
return;
|
||||
@ -199,6 +202,14 @@ void InstanceSettingsPage::applySettings()
|
||||
m_settings->reset("PostExitCommand");
|
||||
}
|
||||
|
||||
// Environment Variables
|
||||
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();
|
||||
m_settings->set("OverrideNativeWorkarounds", workarounds);
|
||||
@ -318,6 +329,9 @@ void InstanceSettingsPage::loadSettings()
|
||||
ui->customCommands->initialize(true, m_settings->get("OverrideCommands").toBool(), m_settings->get("PreLaunchCommand").toString(),
|
||||
m_settings->get("WrapperCommand").toString(), m_settings->get("PostExitCommand").toString());
|
||||
|
||||
// Environment variables
|
||||
ui->environmentVariables->initialize(true, m_settings->get("OverrideEnv").toBool(), m_settings->get("Env").toMap());
|
||||
|
||||
// Workarounds
|
||||
ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool());
|
||||
ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool());
|
||||
@ -484,6 +498,7 @@ void InstanceSettingsPage::retranslate()
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
ui->customCommands->retranslate(); // TODO: why is this seperate from the others?
|
||||
ui->environmentVariables->retranslate();
|
||||
}
|
||||
|
||||
void InstanceSettingsPage::updateThresholds()
|
||||
|
@ -35,13 +35,10 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="settingsTabs">
|
||||
<property name="tabShape">
|
||||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="minecraftTab">
|
||||
<widget class="QWidget" name="minecraftPage">
|
||||
<attribute name="title">
|
||||
<string notr="true">Java</string>
|
||||
</attribute>
|
||||
@ -254,7 +251,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="javaTab">
|
||||
<widget class="QWidget" name="javaPage">
|
||||
<attribute name="title">
|
||||
<string>Game windows</string>
|
||||
</attribute>
|
||||
@ -414,7 +411,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab">
|
||||
<widget class="QWidget" name="customCommandsPage">
|
||||
<attribute name="title">
|
||||
<string>Custom commands</string>
|
||||
</attribute>
|
||||
@ -424,6 +421,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="environmentVariablesPage">
|
||||
<attribute name="title">
|
||||
<string>Environment variables</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_16">
|
||||
<item>
|
||||
<widget class="EnvironmentVariables" name="environmentVariables" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="workaroundsPage">
|
||||
<attribute name="title">
|
||||
<string>Workarounds</string>
|
||||
@ -736,6 +743,12 @@
|
||||
<header>ui/widgets/CustomCommands.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>EnvironmentVariables</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>ui/widgets/EnvironmentVariables.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>openGlobalJavaSettingsButton</tabstop>
|
||||
|
Reference in New Issue
Block a user