From 36c06eed8bd18d854172c94b6e25a75e44425493 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 4 Aug 2024 22:48:02 -0400 Subject: [PATCH] Add a utility function to check the SteamDeck environment variable --- autotests/utilitytest.cpp | 12 ++++++++++++ launcher/include/utility.h | 1 + launcher/src/launchercore.cpp | 2 +- launcher/src/main.cpp | 11 +++-------- launcher/src/utility.cpp | 7 ++++++- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/autotests/utilitytest.cpp b/autotests/utilitytest.cpp index f52123e..12cb304 100644 --- a/autotests/utilitytest.cpp +++ b/autotests/utilitytest.cpp @@ -52,6 +52,18 @@ private Q_SLOTS: Utility::writeVersion(verFile.fileName(), QStringLiteral("2023.09.15.0000.0000")); QCOMPARE(Utility::readVersion(verFile.fileName()), QStringLiteral("2023.09.15.0000.0000")); } + + void testIsSteamDeck() + { + QCOMPARE(Utility::isSteamDeck(), false); + + qputenv("SteamDeck", "0"); + QCOMPARE(Utility::isSteamDeck(), false); + + qputenv("SteamDeck", "1"); + + QCOMPARE(Utility::isSteamDeck(), true); + } }; QTEST_MAIN(UtilityTest) diff --git a/launcher/include/utility.h b/launcher/include/utility.h index 7fd5716..554fc6e 100644 --- a/launcher/include/utility.h +++ b/launcher/include/utility.h @@ -14,4 +14,5 @@ void createPathIfNeeded(const QDir &dir); void setSSL(QNetworkRequest &request); QString readVersion(const QString &path); void writeVersion(const QString &path, const QString &version); +bool isSteamDeck(); } \ No newline at end of file diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index 5759c14..27d8915 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -313,7 +313,7 @@ bool LauncherCore::isSteam() const bool LauncherCore::isSteamDeck() const { - return qEnvironmentVariable("SteamDeck") == QStringLiteral("1"); + return Utility::isSteamDeck(); } bool LauncherCore::isWindows() diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index 86576de..0ef03a4 100755 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -17,6 +16,7 @@ #include "launchercore.h" #include "logger.h" #include "physis_logger.h" +#include "utility.h" #ifdef Q_OS_WIN #include @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) QIcon::setThemeName(QStringLiteral("Breeze")); #endif - if (qEnvironmentVariable("SteamDeck") == QStringLiteral("1")) { + if (Utility::isSteamDeck()) { qputenv("QT_SCALE_FACTOR", "1.25"); qputenv("QT_QUICK_CONTROLS_MOBILE", "1"); } @@ -121,7 +121,6 @@ int main(int argc, char *argv[]) parser.showVersion(); } - bool isSteamDeck = false; if (parser.isSet(steamOption)) { const QStringList args = parser.positionalArguments(); // Steam tries to use as a compatibility tool, running installation scripts (like DirectX), so try to ignore it. @@ -130,14 +129,10 @@ int main(int argc, char *argv[]) } } - if (qEnvironmentVariable("SteamDeck") == QStringLiteral("1")) { - isSteamDeck = true; - } - #if defined(Q_OS_LINUX) // Default to org.kde.desktop style unless the user forces another style if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { - if (isSteamDeck) { + if (Utility::isSteamDeck()) { QQuickStyle::setStyle(QStringLiteral("org.kde.breeze")); } else { QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); diff --git a/launcher/src/utility.cpp b/launcher/src/utility.cpp index 04df639..025be11 100644 --- a/launcher/src/utility.cpp +++ b/launcher/src/utility.cpp @@ -48,4 +48,9 @@ void Utility::writeVersion(const QString &path, const QString &version) verFile.open(QIODevice::WriteOnly | QIODevice::Text); verFile.write(version.toUtf8()); verFile.close(); -} \ No newline at end of file +} + +bool Utility::isSteamDeck() +{ + return qEnvironmentVariable("SteamDeck") == QStringLiteral("1"); +}