1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 11:47:46 +00:00
astra/launcher/src/main.cpp

151 lines
5.7 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#include <KAboutData>
#include <KIconTheme>
#include <KLocalizedContext>
#include <KLocalizedString>
#include <QGuiApplication> // NOTE: do not remove this, if your IDE suggests to do so
#include <QQuickStyle>
#include <kdsingleapplication.h>
2023-09-16 18:37:42 -04:00
#include <qcoroqml.h>
#ifdef HAVE_WEBVIEW
#include <QtWebView>
#endif
#include "astra-version.h"
#include "launchercore.h"
#include "logger.h"
2023-10-10 16:47:26 -04:00
#include "physis_logger.h"
#include "utility.h"
using namespace Qt::StringLiterals;
int main(int argc, char *argv[])
{
#ifdef HAVE_WEBVIEW
2023-09-16 17:32:38 -04:00
QtWebView::initialize();
#endif
KIconTheme::initTheme();
2023-08-18 22:21:38 -04:00
const QGuiApplication app(argc, argv);
const KDSingleApplication singleApplication;
if (!singleApplication.isPrimaryInstance()) {
return 0;
}
// Default to a sensible message pattern
if (qEnvironmentVariableIsEmpty("QT_MESSAGE_PATTERN")) {
qputenv("QT_MESSAGE_PATTERN", "[%{time yyyy-MM-dd h:mm:ss.zzz}] %{if-category}[%{category}] %{endif}[%{type}] %{message}");
}
KLocalizedString::setApplicationDomain("astra");
KAboutData about(QStringLiteral("astra"),
i18n("Astra"),
QStringLiteral(ASTRA_VERSION_STRING),
i18n("FFXIV Launcher"),
KAboutLicense::GPL_V3,
2025-02-01 10:02:21 -05:00
i18n("© 2021-2025 Joshua Goins"));
about.setOtherText(
i18n("This software requires that you have a legitimate and active subscription to FINAL FANTASY XIV. By using this software, you may be in violation "
"of your User Agreement.\n\nFINAL FANTASY, FINAL FANTASY XIV, FFXIV, SQUARE ENIX, and the SQUARE ENIX logo are registered trademarks or "
"trademarks of Square Enix Holdings Co., Ltd."));
about.addAuthor(i18n("Joshua Goins"),
i18n("Maintainer"),
QStringLiteral("josh@redstrate.com"),
QStringLiteral("https://redstrate.com/"),
QUrl(QStringLiteral("https://redstrate.com/rss-image.png")));
about.setHomepage(QStringLiteral("https://xiv.zone/astra"));
about.addComponent(QStringLiteral("physis"),
i18n("Library to access FFXIV data"),
QString::fromLatin1(physis_get_physis_version()),
QStringLiteral("https://xiv.zone/physis"),
KAboutLicense::GPL_V3);
about.addComponent(QStringLiteral("libphysis"),
i18n("C bindings for physis"),
QString::fromLatin1(physis_get_libphysis_version()),
2024-05-22 19:21:11 -04:00
QStringLiteral("https://github.com/redstrate/libphysis"),
KAboutLicense::GPL_V3);
about.addComponent(QStringLiteral("KDSingleApplication"),
i18n("Helper class for single-instance policy applications "),
QStringLiteral("1.1.1"),
QStringLiteral("https://github.com/KDAB/KDSingleApplication"),
KAboutLicense::MIT);
about.addComponent(QStringLiteral("libcotp"),
i18n(" C library that generates TOTP and HOTP "),
QStringLiteral("3.0.0"),
QStringLiteral("https://github.com/paolostivanin/libcotp"),
KAboutLicense::Unknown);
about.setDesktopFileName(QStringLiteral("zone.xiv.astra"));
2024-05-22 19:21:11 -04:00
about.setBugAddress(QByteArrayLiteral("https://github.com/redstrate/astra/issues"));
about.setComponentName(QStringLiteral("astra"));
about.setProgramLogo(QStringLiteral("zone.xiv.astra"));
2023-12-22 16:03:14 -05:00
about.setOrganizationDomain(QByteArrayLiteral("xiv.zone"));
KAboutData::setApplicationData(about);
2023-12-31 17:23:55 -05:00
initializeLogging();
setup_physis_logging();
QCommandLineParser parser;
2023-12-23 10:19:25 -05:00
about.setupCommandLine(&parser);
QCommandLineOption steamOption(QStringLiteral("steam"), QString(), QStringLiteral("verb"));
steamOption.setFlags(QCommandLineOption::HiddenFromHelp);
parser.addOption(steamOption);
parser.parse(QCoreApplication::arguments());
about.processCommandLine(&parser);
// We must handle these manually, since we use parse() and not process()
2023-12-23 10:19:25 -05:00
if (parser.isSet(QStringLiteral("help")) || parser.isSet(QStringLiteral("help-all"))) {
parser.showHelp();
}
if (parser.isSet(QStringLiteral("version"))) {
parser.showVersion();
}
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.
if (!args.empty() && !args.join(QLatin1Char(';')).contains("ffxivboot.exe"_L1)) {
return 0;
}
}
#if defined(Q_OS_LINUX)
// Default to org.kde.desktop style unless the user forces another style
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
if (Utility::isSteamDeck()) {
QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
} else {
QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
}
}
#endif
2023-09-16 18:37:42 -04:00
QCoro::Qml::registerTypes();
QQmlApplicationEngine engine;
2023-09-16 18:01:02 -04:00
const auto core = engine.singletonInstance<LauncherCore *>(QStringLiteral("zone.xiv.astra"), QStringLiteral("LauncherCore"));
if (parser.isSet(steamOption)) {
core->initializeSteam();
}
2023-09-16 18:01:02 -04:00
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit);
2023-09-16 17:41:51 -04:00
engine.loadFromModule(QStringLiteral("zone.xiv.astra"), QStringLiteral("Main"));
if (engine.rootObjects().isEmpty()) {
return -1;
}
return QCoreApplication::exec();
}