mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 11:47:46 +00:00
Add QCoro for coroutine goodness
This commit is contained in:
parent
7605ce7a53
commit
2b3ee3da89
5 changed files with 60 additions and 42 deletions
|
@ -48,6 +48,9 @@ find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS
|
||||||
WebView)
|
WebView)
|
||||||
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n Config CoreAddons)
|
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n Config CoreAddons)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
find_package(QCoro6 REQUIRED COMPONENTS Core Network Qml)
|
||||||
|
qcoro_enable_coroutines()
|
||||||
|
|
||||||
qt_policy(SET QTP0001 NEW)
|
qt_policy(SET QTP0001 NEW)
|
||||||
|
|
||||||
if (ENABLE_WATCHDOG)
|
if (ENABLE_WATCHDOG)
|
||||||
|
|
|
@ -86,7 +86,10 @@ target_link_libraries(astra PRIVATE
|
||||||
KF6::I18n
|
KF6::I18n
|
||||||
KF6::ConfigCore
|
KF6::ConfigCore
|
||||||
KF6::ConfigGui
|
KF6::ConfigGui
|
||||||
KF6::CoreAddons)
|
KF6::CoreAddons
|
||||||
|
QCoro::Core
|
||||||
|
QCoro::Network
|
||||||
|
QCoro::Qml)
|
||||||
|
|
||||||
if (ENABLE_WATCHDOG)
|
if (ENABLE_WATCHDOG)
|
||||||
target_sources(astra PRIVATE
|
target_sources(astra PRIVATE
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QtQml>
|
#include <QtQml>
|
||||||
|
#include <qcorotask.h>
|
||||||
|
|
||||||
#include "accountmanager.h"
|
#include "accountmanager.h"
|
||||||
#include "headline.h"
|
#include "headline.h"
|
||||||
|
@ -208,6 +209,8 @@ private:
|
||||||
|
|
||||||
bool checkIfInPath(const QString &program);
|
bool checkIfInPath(const QString &program);
|
||||||
|
|
||||||
|
QCoro::Task<> fetchNews();
|
||||||
|
|
||||||
SteamAPI *steamApi = nullptr;
|
SteamAPI *steamApi = nullptr;
|
||||||
|
|
||||||
bool m_loadingFinished = false;
|
bool m_loadingFinished = false;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <qcoronetworkreply.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#ifdef ENABLE_GAMEMODE
|
#ifdef ENABLE_GAMEMODE
|
||||||
|
@ -574,6 +575,11 @@ void LauncherCore::setSquareEnixLoginServer(const QString &value)
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherCore::refreshNews()
|
void LauncherCore::refreshNews()
|
||||||
|
{
|
||||||
|
fetchNews();
|
||||||
|
}
|
||||||
|
|
||||||
|
QCoro::Task<> LauncherCore::fetchNews()
|
||||||
{
|
{
|
||||||
QUrlQuery query;
|
QUrlQuery query;
|
||||||
query.addQueryItem("lang", "en-us");
|
query.addQueryItem("lang", "en-us");
|
||||||
|
@ -594,7 +600,8 @@ void LauncherCore::refreshNews()
|
||||||
.toUtf8());
|
.toUtf8());
|
||||||
|
|
||||||
auto reply = mgr->get(request);
|
auto reply = mgr->get(request);
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [this, reply] {
|
co_await reply;
|
||||||
|
|
||||||
auto document = QJsonDocument::fromJson(reply->readAll());
|
auto document = QJsonDocument::fromJson(reply->readAll());
|
||||||
|
|
||||||
auto headline = new Headline(this);
|
auto headline = new Headline(this);
|
||||||
|
@ -643,7 +650,6 @@ void LauncherCore::refreshNews()
|
||||||
|
|
||||||
m_headline = headline;
|
m_headline = headline;
|
||||||
Q_EMIT newsChanged();
|
Q_EMIT newsChanged();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Headline *LauncherCore::headline()
|
Headline *LauncherCore::headline()
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QQuickStyle>
|
#include <QQuickStyle>
|
||||||
#include <QtWebView>
|
#include <QtWebView>
|
||||||
|
#include <qcoroqml.h>
|
||||||
|
|
||||||
#include "astra-version.h"
|
#include "astra-version.h"
|
||||||
#include "compatibilitytoolinstaller.h"
|
#include "compatibilitytoolinstaller.h"
|
||||||
|
@ -76,6 +77,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QCoro::Qml::registerTypes();
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
auto core = engine.singletonInstance<LauncherCore *>(QStringLiteral("zone.xiv.astra"), QStringLiteral("LauncherCore"));
|
auto core = engine.singletonInstance<LauncherCore *>(QStringLiteral("zone.xiv.astra"), QStringLiteral("LauncherCore"));
|
||||||
|
|
Loading…
Add table
Reference in a new issue