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