1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-22 20:47:45 +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();
AccountManager *accountManager();
void setIsSteam(bool isSteam);
void initializeSteam();
/*
* 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:
explicit SteamAPI(LauncherCore &core, QObject *parent = nullptr);
~SteamAPI();
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)
{
m_steamApi->setLauncherMode(false);
if (m_steamApi != nullptr) {
m_steamApi->setLauncherMode(false);
}
beginGameExecutable(profile, auth);
}
@ -397,13 +399,10 @@ LauncherCore::LauncherCore()
m_sapphireLauncher = new SapphireLauncher(*this, this);
m_squareLauncher = new SquareLauncher(*this, this);
m_squareBoot = new SquareBoot(*this, *m_squareLauncher, this);
m_steamApi = new SteamAPI(*this, this);
m_profileManager = new ProfileManager(*this, this);
m_accountManager = new AccountManager(*this, this);
readInitialInformation();
m_steamApi->setLauncherMode(true);
}
bool LauncherCore::checkIfInPath(const QString &program)
@ -765,12 +764,11 @@ bool LauncherCore::isSteam() const
bool LauncherCore::isSteamDeck() const
{
return m_steamApi->isDeck();
}
void LauncherCore::setIsSteam(bool isSteam)
{
m_isSteam = isSteam;
if (m_steamApi != nullptr) {
return m_steamApi->isDeck();
} else {
return false;
}
}
Profile *LauncherCore::currentProfile() const
@ -797,3 +795,10 @@ void LauncherCore::clearAvatarCache()
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 <QApplication>
#include <QCommandLineParser>
#include <QMessageBox>
#include <QQuickStyle>
#include <QtWebView>
#include <qcoroqml.h>
@ -67,24 +68,37 @@ int main(int argc, char *argv[])
parser.parse(QCoreApplication::arguments());
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)) {
#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();
// 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;
}
}
#endif
QCoro::Qml::registerTypes();
QQmlApplicationEngine engine;
#ifdef ENABLE_STEAM
auto core = engine.singletonInstance<LauncherCore *>(QStringLiteral("zone.xiv.astra"), QStringLiteral("LauncherCore"));
core->setIsSteam(parser.isSet(steamOption));
#endif
if (parser.isSet(steamOption)) {
core->initializeSteam();
}
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit);

View file

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