Merge pull request #1034 from Scrumplex/detect-performance-features

This commit is contained in:
Sefa Eyeoglu 2022-09-05 17:45:17 +02:00 committed by GitHub
commit 8e3356f11a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 68 additions and 18 deletions

View File

@ -113,6 +113,11 @@
#include <sys.h>
#ifdef Q_OS_LINUX
#include <dlfcn.h>
#include "gamemode_client.h"
#endif
#if defined Q_OS_WIN32
#ifndef WIN32_LEAN_AND_MEAN
@ -920,6 +925,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
{
return;
}
updateCapabilities();
performMainStartupAction();
}
@ -1568,14 +1575,30 @@ shared_qobject_ptr<Meta::Index> Application::metadataIndex()
return m_metadataIndex;
}
Application::Capabilities Application::currentCapabilities()
void Application::updateCapabilities()
{
Capabilities c;
m_capabilities = None;
if (!getMSAClientID().isEmpty())
c |= SupportsMSA;
m_capabilities |= SupportsMSA;
if (!getFlameAPIKey().isEmpty())
c |= SupportsFlame;
return c;
m_capabilities |= SupportsFlame;
#ifdef Q_OS_LINUX
if (gamemode_query_status() >= 0)
m_capabilities |= SupportsGameMode;
{
void *dummy = dlopen("libMangoHud_dlsym.so", RTLD_LAZY);
// try normal variant as well
if (dummy == NULL)
dummy = dlopen("libMangoHud.so", RTLD_LAZY);
if (dummy != NULL) {
dlclose(dummy);
m_capabilities |= SupportsMangoHud;
}
}
#endif
}
QString Application::getJarPath(QString jarFile)

View File

@ -95,6 +95,8 @@ public:
SupportsMSA = 1 << 0,
SupportsFlame = 1 << 1,
SupportsGameMode = 1 << 2,
SupportsMangoHud = 1 << 3,
};
Q_DECLARE_FLAGS(Capabilities, Capability)
@ -162,7 +164,7 @@ public:
shared_qobject_ptr<Meta::Index> metadataIndex();
Capabilities currentCapabilities();
void updateCapabilities();
/*!
* Finds and returns the full path to a jar file.
@ -180,6 +182,10 @@ public:
return m_rootPath;
}
const Capabilities capabilities() {
return m_capabilities;
}
/*!
* Opens a json file using either a system default editor, or, if not empty, the editor
* specified in the settings
@ -258,6 +264,7 @@ private:
QString m_rootPath;
Status m_status = Application::StartingUp;
Capabilities m_capabilities;
#ifdef Q_OS_MACOS
Qt::ApplicationState m_prevAppState = Qt::ApplicationInactive;

View File

@ -455,13 +455,11 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment()
QProcessEnvironment env = createEnvironment();
#ifdef Q_OS_LINUX
if (settings()->get("EnableMangoHud").toBool())
if (settings()->get("EnableMangoHud").toBool() && APPLICATION->capabilities() & Application::SupportsMangoHud)
{
auto preload = env.value("LD_PRELOAD", "") + ":libMangoHud_dlsym.so:libMangoHud.so";
auto lib_path = env.value("LD_LIBRARY_PATH", "") + ":/usr/local/$LIB/mangohud/:/usr/$LIB/mangohud/";
env.insert("LD_PRELOAD", preload);
env.insert("LD_LIBRARY_PATH", lib_path);
env.insert("MANGOHUD", "1");
}

View File

@ -21,6 +21,8 @@
#include <FileSystem.h>
#include <Commandline.h>
#include "Application.h"
#ifdef Q_OS_LINUX
#include "gamemode_client.h"
#endif
@ -86,7 +88,7 @@ void DirectJavaLaunch::executeTask()
}
#ifdef Q_OS_LINUX
if (instance->settings()->get("EnableFeralGamemode").toBool())
if (instance->settings()->get("EnableFeralGamemode").toBool() && APPLICATION->capabilities() & Application::SupportsGameMode)
{
auto pid = m_process.processId();
if (pid)

View File

@ -162,7 +162,7 @@ void LauncherPartLaunch::executeTask()
}
#ifdef Q_OS_LINUX
if (instance->settings()->get("EnableFeralGamemode").toBool())
if (instance->settings()->get("EnableFeralGamemode").toBool() && APPLICATION->capabilities() & Application::SupportsGameMode)
{
auto pid = m_process.processId();
if (pid)

View File

@ -118,7 +118,7 @@ void Download::executeTask()
}
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
if (APPLICATION->currentCapabilities() & Application::SupportsFlame
if (APPLICATION->capabilities() & Application::SupportsFlame
&& request.url().host().contains("api.curseforge.com")) {
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
};

View File

@ -216,7 +216,7 @@ namespace Net {
}
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
if (APPLICATION->currentCapabilities() & Application::SupportsFlame
if (APPLICATION->capabilities() & Application::SupportsFlame
&& request.url().host().contains("api.curseforge.com")) {
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
}

View File

@ -122,7 +122,7 @@ QList<BasePage *> ModDownloadDialog::getPages()
QList<BasePage *> pages;
pages.append(new ModrinthModPage(this, m_instance));
if (APPLICATION->currentCapabilities() & Application::SupportsFlame)
if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(new FlameModPage(this, m_instance));
return pages;

View File

@ -157,7 +157,7 @@ QList<BasePage *> NewInstanceDialog::getPages()
pages.append(new VanillaPage(this));
pages.append(importPage);
pages.append(new AtlPage(this));
if (APPLICATION->currentCapabilities() & Application::SupportsFlame)
if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(new FlamePage(this));
pages.append(new FtbPage(this));
pages.append(new LegacyFTB::Page(this));

View File

@ -96,7 +96,7 @@ AccountListPage::AccountListPage(QWidget *parent)
updateButtonStates();
// Xbox authentication won't work without a client identifier, so disable the button if it is missing
if (~APPLICATION->currentCapabilities() & Application::SupportsMSA) {
if (~APPLICATION->capabilities() & Application::SupportsMSA) {
ui->actionAddMicrosoft->setVisible(false);
ui->actionAddMicrosoft->setToolTip(tr("No Microsoft Authentication client ID was set."));
}

View File

@ -122,6 +122,16 @@ void MinecraftPage::loadSettings()
ui->perfomanceGroupBox->setVisible(false);
#endif
if (!(APPLICATION->capabilities() & Application::SupportsGameMode)) {
ui->enableFeralGamemodeCheck->setDisabled(true);
ui->enableFeralGamemodeCheck->setToolTip(tr("Feral Interactive's GameMode could not be found on your system."));
}
if (!(APPLICATION->capabilities() & Application::SupportsMangoHud)) {
ui->enableMangoHud->setDisabled(true);
ui->enableMangoHud->setToolTip(tr("MangoHud could not be found on your system."));
}
ui->showGameTime->setChecked(s->get("ShowGameTime").toBool());
ui->showGlobalGameTime->setChecked(s->get("ShowGlobalGameTime").toBool());
ui->recordGameTime->setChecked(s->get("RecordGameTime").toBool());

View File

@ -352,6 +352,16 @@ void InstanceSettingsPage::loadSettings()
ui->settingsTabs->setTabVisible(ui->settingsTabs->indexOf(ui->performancePage), false);
#endif
if (!(APPLICATION->capabilities() & Application::SupportsGameMode)) {
ui->enableFeralGamemodeCheck->setDisabled(true);
ui->enableFeralGamemodeCheck->setToolTip(tr("Feral Interactive's GameMode could not be found on your system."));
}
if (!(APPLICATION->capabilities() & Application::SupportsMangoHud)) {
ui->enableMangoHud->setDisabled(true);
ui->enableMangoHud->setToolTip(tr("MangoHud could not be found on your system."));
}
// Miscellanous
ui->gameTimeGroupBox->setChecked(m_settings->get("OverrideGameTime").toBool());
ui->showGameTime->setChecked(m_settings->get("ShowGameTime").toBool());