mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-22 12:47:44 +00:00
Add option to close automatically when game is launched
This commit is contained in:
parent
d10525a24f
commit
5e1fc20276
5 changed files with 294 additions and 217 deletions
|
@ -197,7 +197,14 @@ void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth au
|
|||
arguments.append(argJoined);
|
||||
}
|
||||
|
||||
connect(gameProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
[=](int exitCode, QProcess::ExitStatus exitStatus){
|
||||
gameClosed();
|
||||
});
|
||||
|
||||
launchExecutable(profile, gameProcess, arguments);
|
||||
|
||||
successfulLaunch();
|
||||
}
|
||||
|
||||
void LauncherCore::launchExecutable(const ProfileSettings& profile, const QStringList args) {
|
||||
|
@ -269,6 +276,8 @@ QString LauncherCore::readVersion(QString path) {
|
|||
void LauncherCore::readInitialInformation() {
|
||||
defaultProfileIndex = settings.value("defaultProfile", 0).toInt();
|
||||
|
||||
appSettings.closeWhenLaunched = settings.value("closeWhenLaunched", true).toBool();
|
||||
|
||||
gamescopeAvailable = checkIfInPath("gamescope");
|
||||
gamemodeAvailable = checkIfInPath("gamemoderun");
|
||||
|
||||
|
@ -512,6 +521,7 @@ int LauncherCore::deleteProfile(QString name) {
|
|||
|
||||
void LauncherCore::saveSettings() {
|
||||
settings.setValue("defaultProfile", defaultProfileIndex);
|
||||
settings.setValue("closeWhenLaunched", appSettings.closeWhenLaunched);
|
||||
|
||||
for(int i = 0; i < profileSettings.size(); i++) {
|
||||
const auto& profile = profileSettings[i];
|
||||
|
|
|
@ -57,6 +57,10 @@ struct ProfileSettings {
|
|||
bool useSteam = false;
|
||||
};
|
||||
|
||||
struct AppSettings {
|
||||
bool closeWhenLaunched = true;
|
||||
};
|
||||
|
||||
struct LoginInformation {
|
||||
const ProfileSettings* settings = nullptr;
|
||||
|
||||
|
@ -112,9 +116,13 @@ public:
|
|||
bool gamescopeAvailable = false;
|
||||
bool gamemodeAvailable = false;
|
||||
|
||||
AppSettings appSettings;
|
||||
|
||||
int defaultProfileIndex = 0;
|
||||
signals:
|
||||
void settingsChanged();
|
||||
void successfulLaunch();
|
||||
void gameClosed();
|
||||
|
||||
private:
|
||||
void readExpansionVersions(ProfileSettings& info, int max);
|
||||
|
|
|
@ -146,6 +146,15 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo
|
|||
}
|
||||
});
|
||||
|
||||
connect(&core, &LauncherCore::successfulLaunch, [&] {
|
||||
hide();
|
||||
});
|
||||
|
||||
connect(&core, &LauncherCore::gameClosed, [&] {
|
||||
if(core.appSettings.closeWhenLaunched)
|
||||
QCoreApplication::quit();
|
||||
});
|
||||
|
||||
reloadControls();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,25 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
auto tabWidget = new QTabWidget();
|
||||
mainLayout->addWidget(tabWidget);
|
||||
|
||||
// general tab
|
||||
{
|
||||
auto generalTabWidget = new QWidget();
|
||||
tabWidget->addTab(generalTabWidget, "General");
|
||||
|
||||
auto layout = new QFormLayout();
|
||||
generalTabWidget->setLayout(layout);
|
||||
|
||||
closeWhenLaunched = new QCheckBox("Close Astra when game is launched");
|
||||
connect(closeWhenLaunched, &QCheckBox::stateChanged, [&](int state) {
|
||||
core.appSettings.closeWhenLaunched = state;
|
||||
|
||||
core.saveSettings();
|
||||
});
|
||||
layout->addWidget(closeWhenLaunched);
|
||||
}
|
||||
|
||||
// profile tab
|
||||
{
|
||||
auto profileTabWidget = new QWidget();
|
||||
tabWidget->addTab(profileTabWidget, "Profiles");
|
||||
|
||||
|
@ -36,7 +55,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
profileWidget->addItem("INVALID *DEBUG*");
|
||||
profileWidget->setCurrentRow(0);
|
||||
|
||||
connect(profileWidget, &QListWidget::currentRowChanged, this, &SettingsWindow::reloadControls);
|
||||
connect(profileWidget, &QListWidget::currentRowChanged, this,
|
||||
&SettingsWindow::reloadControls);
|
||||
|
||||
profileLayout->addWidget(profileWidget, 0, 0, 0, 1);
|
||||
|
||||
|
@ -50,7 +70,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
deleteProfileButton = new QPushButton("Delete Profile");
|
||||
connect(deleteProfileButton, &QPushButton::pressed, [=] {
|
||||
profileWidget->setCurrentRow(this->core.deleteProfile(getCurrentProfile().name));
|
||||
profileWidget->setCurrentRow(
|
||||
this->core.deleteProfile(getCurrentProfile().name));
|
||||
|
||||
this->core.saveSettings();
|
||||
});
|
||||
|
@ -76,8 +97,12 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
directXCombo->addItem("DirectX 9");
|
||||
gameBoxLayout->addRow("DirectX Version", directXCombo);
|
||||
|
||||
connect(directXCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](int index) {
|
||||
getCurrentProfile().useDX9 = directXCombo->currentIndex() == 1;
|
||||
connect(directXCombo,
|
||||
static_cast<void (QComboBox::*)(int)>(
|
||||
&QComboBox::currentIndexChanged),
|
||||
[=](int index) {
|
||||
getCurrentProfile().useDX9 =
|
||||
directXCombo->currentIndex() == 1;
|
||||
this->core.saveSettings();
|
||||
});
|
||||
|
||||
|
@ -92,7 +117,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
auto selectDirectoryButton = new QPushButton("Select Game Directory");
|
||||
connect(selectDirectoryButton, &QPushButton::pressed, [this] {
|
||||
getCurrentProfile().gamePath = QFileDialog::getExistingDirectory(this, "Open Game Directory");
|
||||
getCurrentProfile().gamePath =
|
||||
QFileDialog::getExistingDirectory(this, "Open Game Directory");
|
||||
|
||||
this->reloadControls();
|
||||
this->core.saveSettings();
|
||||
|
@ -102,9 +128,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
gameDirButtonLayout->addWidget(selectDirectoryButton);
|
||||
|
||||
auto gameDirectoryButton = new QPushButton("Open Game Directory");
|
||||
connect(gameDirectoryButton, &QPushButton::pressed, [this] {
|
||||
openPath(getCurrentProfile().gamePath);
|
||||
});
|
||||
connect(gameDirectoryButton, &QPushButton::pressed,
|
||||
[this] { openPath(getCurrentProfile().gamePath); });
|
||||
gameDirButtonLayout->addWidget(gameDirectoryButton);
|
||||
|
||||
#ifdef ENABLE_WATCHDOG
|
||||
|
@ -129,7 +154,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
encryptArgumentsBox = new QCheckBox();
|
||||
connect(encryptArgumentsBox, &QCheckBox::stateChanged, [=](int) {
|
||||
getCurrentProfile().encryptArguments = encryptArgumentsBox->isChecked();
|
||||
getCurrentProfile().encryptArguments =
|
||||
encryptArgumentsBox->isChecked();
|
||||
|
||||
this->core.saveSettings();
|
||||
});
|
||||
|
@ -139,7 +165,10 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
serverType->insertItem(0, "Square Enix");
|
||||
serverType->insertItem(1, "Sapphire");
|
||||
|
||||
connect(serverType, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](int index) {
|
||||
connect(serverType,
|
||||
static_cast<void (QComboBox::*)(int)>(
|
||||
&QComboBox::currentIndexChanged),
|
||||
[=](int index) {
|
||||
getCurrentProfile().isSapphire = index == 1;
|
||||
|
||||
reloadControls();
|
||||
|
@ -157,7 +186,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
rememberUsernameBox = new QCheckBox();
|
||||
connect(rememberUsernameBox, &QCheckBox::stateChanged, [=](int) {
|
||||
getCurrentProfile().rememberUsername = rememberUsernameBox->isChecked();
|
||||
getCurrentProfile().rememberUsername =
|
||||
rememberUsernameBox->isChecked();
|
||||
|
||||
this->core.saveSettings();
|
||||
});
|
||||
|
@ -165,7 +195,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
rememberPasswordBox = new QCheckBox();
|
||||
connect(rememberPasswordBox, &QCheckBox::stateChanged, [=](int) {
|
||||
getCurrentProfile().rememberPassword = rememberPasswordBox->isChecked();
|
||||
getCurrentProfile().rememberPassword =
|
||||
rememberPasswordBox->isChecked();
|
||||
|
||||
this->core.saveSettings();
|
||||
});
|
||||
|
@ -204,7 +235,10 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
selectWineButton = new QPushButton("Select Wine Executable");
|
||||
wineBoxLayout->addWidget(selectWineButton);
|
||||
|
||||
connect(wineVersionCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
connect(wineVersionCombo,
|
||||
static_cast<void (QComboBox::*)(int)>(
|
||||
&QComboBox::currentIndexChanged),
|
||||
[this](int index) {
|
||||
getCurrentProfile().wineVersion = index;
|
||||
|
||||
this->core.readWineInfo(getCurrentProfile());
|
||||
|
@ -213,7 +247,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
});
|
||||
|
||||
connect(selectWineButton, &QPushButton::pressed, [this] {
|
||||
getCurrentProfile().winePath = QFileDialog::getOpenFileName(this, "Open Wine Executable");
|
||||
getCurrentProfile().winePath =
|
||||
QFileDialog::getOpenFileName(this, "Open Wine Executable");
|
||||
|
||||
this->core.saveSettings();
|
||||
this->reloadControls();
|
||||
|
@ -230,7 +265,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
auto selectPrefixButton = new QPushButton("Select Wine Prefix");
|
||||
connect(selectPrefixButton, &QPushButton::pressed, [this] {
|
||||
getCurrentProfile().winePrefixPath = QFileDialog::getExistingDirectory(this, "Open Wine Prefix");
|
||||
getCurrentProfile().winePrefixPath =
|
||||
QFileDialog::getExistingDirectory(this, "Open Wine Prefix");
|
||||
|
||||
this->core.saveSettings();
|
||||
this->reloadControls();
|
||||
|
@ -238,9 +274,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
winePrefixButtonLayout->addWidget(selectPrefixButton);
|
||||
|
||||
auto openPrefixButton = new QPushButton("Open Wine Prefix");
|
||||
connect(openPrefixButton, &QPushButton::pressed, [this] {
|
||||
openPath(getCurrentProfile().winePrefixPath);
|
||||
});
|
||||
connect(openPrefixButton, &QPushButton::pressed,
|
||||
[this] { openPath(getCurrentProfile().winePrefixPath); });
|
||||
winePrefixButtonLayout->addWidget(openPrefixButton);
|
||||
|
||||
auto enableDXVKhud = new QCheckBox("Enable DXVK HUD");
|
||||
|
@ -248,17 +283,21 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
connect(enableDXVKhud, &QCheckBox::stateChanged, [this](int state) {
|
||||
getCurrentProfile().enableDXVKhud = state;
|
||||
this->core.settings.setValue("enableDXVKhud", static_cast<bool>(state));
|
||||
this->core.settings.setValue("enableDXVKhud",
|
||||
static_cast<bool>(state));
|
||||
});
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
useEsync = new QCheckBox("Use Better Sync Primitives (Esync, Fsync, and Futex2)");
|
||||
useEsync = new QCheckBox(
|
||||
"Use Better Sync Primitives (Esync, Fsync, and Futex2)");
|
||||
wineBoxLayout->addWidget(useEsync);
|
||||
|
||||
auto esyncLabel = new QPushButton("?");
|
||||
connect(esyncLabel, &QPushButton::pressed, [esyncLabel] {
|
||||
QToolTip::showText(esyncLabel->mapToGlobal(QPoint()), "This may improve game performance, but requires a Wine and kernel with the patches included.");
|
||||
QToolTip::showText(
|
||||
esyncLabel->mapToGlobal(QPoint()),
|
||||
"This may improve game performance, but requires a Wine and kernel with the patches included.");
|
||||
});
|
||||
wineBoxLayout->addWidget(esyncLabel);
|
||||
|
||||
|
@ -278,13 +317,16 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
auto gamescopeLabel = new QPushButton("?");
|
||||
connect(gamescopeLabel, &QPushButton::pressed, [gamescopeLabel] {
|
||||
QToolTip::showText(gamescopeLabel->mapToGlobal(QPoint()), "Use the micro-compositor compositor that uses Wayland and XWayland to create a nested session.\nIf you primarily use fullscreen mode, this may improve input handling especially on Wayland.");
|
||||
QToolTip::showText(
|
||||
gamescopeLabel->mapToGlobal(QPoint()),
|
||||
"Use the micro-compositor compositor that uses Wayland and XWayland to create a nested session.\nIf you primarily use fullscreen mode, this may improve input handling especially on Wayland.");
|
||||
});
|
||||
gamescopeButtonLayout->addWidget(gamescopeLabel);
|
||||
|
||||
configureGamescopeButton = new QPushButton("Configure...");
|
||||
connect(configureGamescopeButton, &QPushButton::pressed, [&] {
|
||||
auto gamescopeSettingsWindow = new GamescopeSettingsWindow(getCurrentProfile(), this->core, this);
|
||||
auto gamescopeSettingsWindow = new GamescopeSettingsWindow(
|
||||
getCurrentProfile(), this->core, this);
|
||||
gamescopeSettingsWindow->show();
|
||||
});
|
||||
gamescopeButtonLayout->addWidget(configureGamescopeButton);
|
||||
|
@ -301,7 +343,9 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
auto gamemodeLabel = new QPushButton("?");
|
||||
connect(gamemodeLabel, &QPushButton::pressed, [gamemodeLabel] {
|
||||
QToolTip::showText(gamemodeLabel->mapToGlobal(QPoint()), "A special game performance enhancer, which automatically tunes your CPU scheduler among other things. This may improve game performance.");
|
||||
QToolTip::showText(
|
||||
gamemodeLabel->mapToGlobal(QPoint()),
|
||||
"A special game performance enhancer, which automatically tunes your CPU scheduler among other things. This may improve game performance.");
|
||||
});
|
||||
wineBoxLayout->addWidget(gamemodeLabel);
|
||||
|
||||
|
@ -328,6 +372,7 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg
|
|||
|
||||
dalamudVersionLabel = new QLabel();
|
||||
dalamudBoxLayout->addRow("Dalamud Version", dalamudVersionLabel);
|
||||
}
|
||||
|
||||
reloadControls();
|
||||
}
|
||||
|
@ -347,6 +392,8 @@ void SettingsWindow::reloadControls() {
|
|||
}
|
||||
profileWidget->setCurrentRow(oldRow);
|
||||
|
||||
closeWhenLaunched->setChecked(core.appSettings.closeWhenLaunched);
|
||||
|
||||
// deleting the main profile is unsupported behavior
|
||||
deleteProfileButton->setEnabled(core.profileList().size() > 1);
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@ private:
|
|||
QListWidget* profileWidget = nullptr;
|
||||
QPushButton* deleteProfileButton = nullptr;
|
||||
|
||||
// general
|
||||
QCheckBox* closeWhenLaunched = nullptr;
|
||||
|
||||
// game
|
||||
QLineEdit* nameEdit = nullptr;
|
||||
QComboBox* directXCombo = nullptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue