Close after Launch setting

This commit is contained in:
swirl 2022-01-29 19:04:44 -05:00
parent 5abb97362f
commit 0065a29901
No known key found for this signature in database
GPG Key ID: 46507311CD292A08
6 changed files with 36 additions and 0 deletions

View File

@ -717,6 +717,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
// pastebin URL
m_settings->registerSetting("PastebinURL", "https://0x0.st");
m_settings->registerSetting("CloseAfterLaunch", false);
// Init page provider
{
m_globalSettingsProvider = std::make_shared<GenericPageProvider>(tr("Settings"));

View File

@ -25,6 +25,19 @@
LauncherPartLaunch::LauncherPartLaunch(LaunchTask *parent) : LaunchStep(parent)
{
if (APPLICATION->settings()->get("CloseAfterLaunch").toBoolean())
{
std::shared_ptr<QMetaObject::Connection> connection{new QMetaObject::Connection};
*connection = connect(&m_process, &LoggedProcess::log, this, [=](QStringList lines, MessageLevel::Enum level) {
qDebug() << lines;
if (lines.filter(QRegularExpression(".+Backend library: LWJGL version.+")).length() != 0)
{
APPLICATION->closeAllWindows();
disconnect(*connection);
}
});
}
connect(&m_process, &LoggedProcess::log, this, &LauncherPartLaunch::logLines);
connect(&m_process, &LoggedProcess::stateChanged, this, &LauncherPartLaunch::on_state);
}
@ -155,6 +168,8 @@ void LauncherPartLaunch::on_state(LoggedProcess::State state)
}
case LoggedProcess::Finished:
{
if (APPLICATION->settings()->get("CloseAfterLaunch").toBoolean())
APPLICATION->showMainWindow();
m_parent->setPid(-1);
// if the exit code wasn't 0, report this as a crash
auto exitCode = m_process.exitCode();

View File

@ -292,6 +292,7 @@ void LauncherPage::applySettings()
s->set("ShowConsole", ui->showConsoleCheck->isChecked());
s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
s->set("ShowConsoleOnError", ui->showConsoleErrorCheck->isChecked());
s->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
QString consoleFontFamily = ui->consoleFont->currentFont().family();
s->set("ConsoleFont", consoleFontFamily);
s->set("ConsoleFontSize", ui->fontSizeBox->value());
@ -380,6 +381,7 @@ void LauncherPage::loadSettings()
ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool());
ui->showConsoleErrorCheck->setChecked(s->get("ShowConsoleOnError").toBool());
ui->closeAfterLaunchCheck->setChecked(s->get("CloseAfterLaunch").toBool());
QString fontFamily = APPLICATION->settings()->get("ConsoleFont").toString();
QFont consoleFont(fontFamily);
ui->consoleFont->setCurrentFont(consoleFont);

View File

@ -382,6 +382,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="closeAfterLaunchCheck">
<property name="text">
<string>Hide console when game window opens?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -73,12 +73,14 @@ void InstanceSettingsPage::applySettings()
m_settings->set("ShowConsole", ui->showConsoleCheck->isChecked());
m_settings->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
m_settings->set("ShowConsoleOnError", ui->showConsoleErrorCheck->isChecked());
m_settings->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
}
else
{
m_settings->reset("ShowConsole");
m_settings->reset("AutoCloseConsole");
m_settings->reset("ShowConsoleOnError");
m_settings->reset("CloseAfterLaunch");
}
// Window Size
@ -215,6 +217,7 @@ void InstanceSettingsPage::loadSettings()
ui->showConsoleCheck->setChecked(m_settings->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(m_settings->get("AutoCloseConsole").toBool());
ui->showConsoleErrorCheck->setChecked(m_settings->get("ShowConsoleOnError").toBool());
ui->closeAfterLaunchCheck->setChecked(m_settings->get("CloseAfterLaunch").toBool());
// Window Size
ui->windowSizeGroupBox->setChecked(m_settings->get("OverrideWindow").toBool());

View File

@ -336,6 +336,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="closeAfterLaunchCheck">
<property name="text">
<string>Hide console when game window opens?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>