1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-23 04:57:44 +00:00

Refactor parts of the Steam API support

To make the code a bit cleaner, ensure the steam api class is only
initialized if Steam support is needed. Also shuts down the steam api
too.
This commit is contained in:
Joshua Goins 2023-10-08 17:55:13 -04:00
parent f44c392eb0
commit 2662b0e0bb
5 changed files with 44 additions and 25 deletions

View file

@ -87,7 +87,7 @@ public:
ProfileManager *profileManager(); ProfileManager *profileManager();
AccountManager *accountManager(); AccountManager *accountManager();
void setIsSteam(bool isSteam); void initializeSteam();
/* /*
* Begins the login process, and may call SquareBoot or SapphireLauncher depending on the profile type. * Begins the login process, and may call SquareBoot or SapphireLauncher depending on the profile type.

View file

@ -11,6 +11,7 @@ class SteamAPI : public QObject
{ {
public: public:
explicit SteamAPI(LauncherCore &core, QObject *parent = nullptr); explicit SteamAPI(LauncherCore &core, QObject *parent = nullptr);
~SteamAPI();
void setLauncherMode(bool isLauncher); void setLauncherMode(bool isLauncher);

View file

@ -65,7 +65,9 @@ void LauncherCore::buildRequest(const Profile &settings, QNetworkRequest &reques
void LauncherCore::launchGame(Profile &profile, const LoginAuth &auth) void LauncherCore::launchGame(Profile &profile, const LoginAuth &auth)
{ {
if (m_steamApi != nullptr) {
m_steamApi->setLauncherMode(false); m_steamApi->setLauncherMode(false);
}
beginGameExecutable(profile, auth); beginGameExecutable(profile, auth);
} }
@ -397,13 +399,10 @@ LauncherCore::LauncherCore()
m_sapphireLauncher = new SapphireLauncher(*this, this); m_sapphireLauncher = new SapphireLauncher(*this, this);
m_squareLauncher = new SquareLauncher(*this, this); m_squareLauncher = new SquareLauncher(*this, this);
m_squareBoot = new SquareBoot(*this, *m_squareLauncher, this); m_squareBoot = new SquareBoot(*this, *m_squareLauncher, this);
m_steamApi = new SteamAPI(*this, this);
m_profileManager = new ProfileManager(*this, this); m_profileManager = new ProfileManager(*this, this);
m_accountManager = new AccountManager(*this, this); m_accountManager = new AccountManager(*this, this);
readInitialInformation(); readInitialInformation();
m_steamApi->setLauncherMode(true);
} }
bool LauncherCore::checkIfInPath(const QString &program) bool LauncherCore::checkIfInPath(const QString &program)
@ -765,12 +764,11 @@ bool LauncherCore::isSteam() const
bool LauncherCore::isSteamDeck() const bool LauncherCore::isSteamDeck() const
{ {
if (m_steamApi != nullptr) {
return m_steamApi->isDeck(); return m_steamApi->isDeck();
} } else {
return false;
void LauncherCore::setIsSteam(bool isSteam) }
{
m_isSteam = isSteam;
} }
Profile *LauncherCore::currentProfile() const Profile *LauncherCore::currentProfile() const
@ -797,3 +795,10 @@ void LauncherCore::clearAvatarCache()
QDir(cacheLocation).removeRecursively(); QDir(cacheLocation).removeRecursively();
} }
} }
void LauncherCore::initializeSteam()
{
m_isSteam = true;
m_steamApi = new SteamAPI(*this, this);
m_steamApi->setLauncherMode(true);
}

View file

@ -6,6 +6,7 @@
#include <KLocalizedString> #include <KLocalizedString>
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QMessageBox>
#include <QQuickStyle> #include <QQuickStyle>
#include <QtWebView> #include <QtWebView>
#include <qcoroqml.h> #include <qcoroqml.h>
@ -67,24 +68,37 @@ int main(int argc, char *argv[])
parser.parse(QCoreApplication::arguments()); parser.parse(QCoreApplication::arguments());
about.processCommandLine(&parser); about.processCommandLine(&parser);
#ifdef ENABLE_STEAM // We must handle these manually, since we use parse() and not process()
if (parser.isSet("help")) {
parser.showHelp();
}
if (parser.isSet("version")) {
parser.showVersion();
}
if (parser.isSet(steamOption)) { if (parser.isSet(steamOption)) {
#ifndef ENABLE_STEAM
QMessageBox::warning(nullptr,
i18n("Warning"),
i18n("You somehow launched Astra through Steam, despite it not being compiled with Steam support. Some features may not work!"));
#endif
const QStringList args = parser.positionalArguments(); const QStringList args = parser.positionalArguments();
// Steam tries to use as a compatibility tool, running installation scripts (like DirectX), so try to ignore it. // Steam tries to use as a compatibility tool, running installation scripts (like DirectX), so try to ignore it.
if (!args[0].contains(QLatin1String("ffxivboot.exe"))) { if (!args.empty() && !args[0].contains(QLatin1String("ffxivboot.exe"))) {
return 0; return 0;
} }
} }
#endif
QCoro::Qml::registerTypes(); QCoro::Qml::registerTypes();
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
#ifdef ENABLE_STEAM
auto core = engine.singletonInstance<LauncherCore *>(QStringLiteral("zone.xiv.astra"), QStringLiteral("LauncherCore")); auto core = engine.singletonInstance<LauncherCore *>(QStringLiteral("zone.xiv.astra"), QStringLiteral("LauncherCore"));
core->setIsSteam(parser.isSet(steamOption)); if (parser.isSet(steamOption)) {
#endif core->initializeSteam();
}
engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit); QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit);

View file

@ -24,12 +24,15 @@ SteamAPI::SteamAPI(LauncherCore &core, QObject *parent)
#endif #endif
} }
SteamAPI::~SteamAPI()
{
SteamAPI_Shutdown();
}
void SteamAPI::setLauncherMode(bool isLauncher) void SteamAPI::setLauncherMode(bool isLauncher)
{ {
#ifdef ENABLE_STEAM #ifdef ENABLE_STEAM
if (core.isSteam()) {
SteamUtils()->SetGameLauncherMode(isLauncher); SteamUtils()->SetGameLauncherMode(isLauncher);
}
#else #else
Q_UNUSED(isLauncher) Q_UNUSED(isLauncher)
#endif #endif
@ -38,11 +41,7 @@ void SteamAPI::setLauncherMode(bool isLauncher)
bool SteamAPI::isDeck() const bool SteamAPI::isDeck() const
{ {
#ifdef ENABLE_STEAM #ifdef ENABLE_STEAM
if (core.isSteam()) {
return SteamUtils()->IsSteamRunningOnSteamDeck(); return SteamUtils()->IsSteamRunningOnSteamDeck();
} else {
return false;
}
#else #else
return false; return false;
#endif #endif