Add quit launcher after game stops option (Steam Deck)

lecense
This commit is contained in:
dada513 2022-03-23 19:06:17 +01:00
parent c7fdfb8116
commit b1af689546
No known key found for this signature in database
GPG Key ID: 403448C14FA4B33E
8 changed files with 83 additions and 0 deletions

View File

@ -727,6 +727,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_settings->registerSetting("PastebinURL", "https://0x0.st"); m_settings->registerSetting("PastebinURL", "https://0x0.st");
m_settings->registerSetting("CloseAfterLaunch", false); m_settings->registerSetting("CloseAfterLaunch", false);
m_settings->registerSetting("QuitAfterGameStop", false);
// Custom MSA credentials // Custom MSA credentials
m_settings->registerSetting("MSAClientIDOverride", ""); m_settings->registerSetting("MSAClientIDOverride", "");

View File

@ -144,6 +144,8 @@ set(LAUNCH_SOURCES
launch/steps/TextPrint.h launch/steps/TextPrint.h
launch/steps/Update.cpp launch/steps/Update.cpp
launch/steps/Update.h launch/steps/Update.h
launch/steps/QuitAfterGameStop.cpp
launch/steps/QuitAfterGameStop.h
launch/LaunchStep.cpp launch/LaunchStep.cpp
launch/LaunchStep.h launch/LaunchStep.h
launch/LaunchTask.cpp launch/LaunchTask.cpp

View File

@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Copyright (C) 2022 dada513 <dada513@protonmail.com>
*
* 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 "QuitAfterGameStop.h"
#include <launch/LaunchTask.h>
#include "Application.h"
void QuitAfterGameStop::executeTask()
{
APPLICATION->quit();
}

View File

@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Copyright (C) 2022 dada513 <dada513@protonmail.com>
*
* 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 <launch/LaunchStep.h>
class QuitAfterGameStop: public LaunchStep
{
Q_OBJECT
public:
explicit QuitAfterGameStop(LaunchTask *parent) :LaunchStep(parent){};
virtual ~QuitAfterGameStop() {};
virtual void executeTask();
virtual bool canAbort() const
{
return false;
}
};

View File

@ -20,6 +20,7 @@
#include "launch/steps/PreLaunchCommand.h" #include "launch/steps/PreLaunchCommand.h"
#include "launch/steps/TextPrint.h" #include "launch/steps/TextPrint.h"
#include "launch/steps/CheckJava.h" #include "launch/steps/CheckJava.h"
#include "launch/steps/QuitAfterGameStop.h"
#include "minecraft/launch/LauncherPartLaunch.h" #include "minecraft/launch/LauncherPartLaunch.h"
#include "minecraft/launch/DirectJavaLaunch.h" #include "minecraft/launch/DirectJavaLaunch.h"
@ -935,6 +936,11 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
{ {
process->setCensorFilter(createCensorFilterFromSession(session)); process->setCensorFilter(createCensorFilterFromSession(session));
} }
if(APPLICATION->settings()->get("QuitAfterGameStop").toBool())
{
auto step = new QuitAfterGameStop(pptr);
process->appendStep(step);
}
m_launchProcess = process; m_launchProcess = process;
emit launchTaskChanged(m_launchProcess); emit launchTaskChanged(m_launchProcess);
return m_launchProcess; return m_launchProcess;

View File

@ -170,6 +170,7 @@ void LauncherPartLaunch::on_state(LoggedProcess::State state)
{ {
if (APPLICATION->settings()->get("CloseAfterLaunch").toBool()) if (APPLICATION->settings()->get("CloseAfterLaunch").toBool())
APPLICATION->showMainWindow(); APPLICATION->showMainWindow();
m_parent->setPid(-1); m_parent->setPid(-1);
// if the exit code wasn't 0, report this as a crash // if the exit code wasn't 0, report this as a crash
auto exitCode = m_process.exitCode(); auto exitCode = m_process.exitCode();

View File

@ -94,6 +94,7 @@ void MinecraftPage::applySettings()
// Miscellaneous // Miscellaneous
s->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked()); s->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
s->set("QuitAfterGameStop", ui->quitAfterGameStopCheck->isChecked());
} }
void MinecraftPage::loadSettings() void MinecraftPage::loadSettings()
@ -113,6 +114,7 @@ void MinecraftPage::loadSettings()
ui->recordGameTime->setChecked(s->get("RecordGameTime").toBool()); ui->recordGameTime->setChecked(s->get("RecordGameTime").toBool());
ui->closeAfterLaunchCheck->setChecked(s->get("CloseAfterLaunch").toBool()); ui->closeAfterLaunchCheck->setChecked(s->get("CloseAfterLaunch").toBool());
ui->quitAfterGameStopCheck->setChecked(s->get("QuitAfterGameStop").toBool());
} }
void MinecraftPage::retranslate() void MinecraftPage::retranslate()

View File

@ -180,6 +180,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="quitAfterGameStopCheck">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;PolyMC will automatically exit if the game crashes or exists.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Quit PolyMC after game window stops</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>