gamelauncher: use generated DBus proxies

This commit is contained in:
Marco Allegretti 2026-02-15 13:57:23 +01:00
parent d93dbc9ecc
commit 4676b1d9a6

View file

@ -4,13 +4,14 @@
#include "gamelauncher.h" #include "gamelauncher.h"
#include "app.h" #include "app.h"
#include "gamecenter1interface.h"
#include "runner1interface.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDBusArgument> #include <QDBusArgument>
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusConnectionInterface> #include <QDBusConnectionInterface>
#include <QDBusError> #include <QDBusError>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDBusVariant> #include <QDBusVariant>
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
@ -25,7 +26,6 @@ static const QString kGameCenterInterface = QStringLiteral("org.kde.GameCenter1"
static const QString kRunnerService = QStringLiteral("org.kde.ALaKarte.Runner1"); static const QString kRunnerService = QStringLiteral("org.kde.ALaKarte.Runner1");
static const QString kRunnerPath = QStringLiteral("/org/kde/ALaKarte/Runner1"); static const QString kRunnerPath = QStringLiteral("/org/kde/ALaKarte/Runner1");
static const QString kRunnerInterface = QStringLiteral("org.kde.ALaKarte.Runner1");
static bool pingDaemon(QDBusConnection bus) static bool pingDaemon(QDBusConnection bus)
{ {
@ -33,14 +33,15 @@ static bool pingDaemon(QDBusConnection bus)
return false; return false;
} }
QDBusInterface iface(kGameCenterService, kGameCenterPath, kGameCenterInterface, bus); org::kde::GameCenter1 iface(kGameCenterService, kGameCenterPath, bus);
if (!iface.isValid()) { if (!iface.isValid()) {
return false; return false;
} }
iface.setTimeout(2000); iface.setTimeout(2000);
const QDBusReply<QString> reply = iface.call(QStringLiteral("Ping")); QDBusPendingReply<QString> reply = iface.Ping();
return reply.isValid() && reply.value() == QLatin1String("ok"); reply.waitForFinished();
return !reply.isError() && reply.value() == QLatin1String("ok");
} }
static void disconnectDaemonSignals(QDBusConnection bus, GameLauncher *launcher) static void disconnectDaemonSignals(QDBusConnection bus, GameLauncher *launcher)
@ -131,14 +132,15 @@ static bool tryResolveWithRunnerManager(const QVariantMap &spec, QVariantMap &ou
bus.interface()->startService(kRunnerService); bus.interface()->startService(kRunnerService);
} }
QDBusInterface iface(kRunnerService, kRunnerPath, kRunnerInterface, bus); org::kde::ALaKarte::Runner1 iface(kRunnerService, kRunnerPath, bus);
if (!iface.isValid()) { if (!iface.isValid()) {
if (bus.interface()->startService(kRunnerService).isValid()) { if (bus.interface()->startService(kRunnerService).isValid()) {
QDBusInterface retryIface(kRunnerService, kRunnerPath, kRunnerInterface, bus); org::kde::ALaKarte::Runner1 retryIface(kRunnerService, kRunnerPath, bus);
if (retryIface.isValid()) { if (retryIface.isValid()) {
retryIface.setTimeout(2000); retryIface.setTimeout(2000);
const QDBusReply<QVariantMap> retryReply = retryIface.call(QStringLiteral("ResolveLaunch"), spec); QDBusPendingReply<QVariantMap> retryReply = retryIface.ResolveLaunch(spec);
if (retryReply.isValid()) { retryReply.waitForFinished();
if (!retryReply.isError()) {
out = unwrapVariantMap(retryReply.value()); out = unwrapVariantMap(retryReply.value());
return true; return true;
} }
@ -148,17 +150,19 @@ static bool tryResolveWithRunnerManager(const QVariantMap &spec, QVariantMap &ou
} }
iface.setTimeout(2000); iface.setTimeout(2000);
const QDBusReply<QVariantMap> reply = iface.call(QStringLiteral("ResolveLaunch"), spec); QDBusPendingReply<QVariantMap> reply = iface.ResolveLaunch(spec);
if (!reply.isValid()) { reply.waitForFinished();
if (reply.isError()) {
if (reply.error().type() == QDBusError::ServiceUnknown) { if (reply.error().type() == QDBusError::ServiceUnknown) {
bus.interface()->startService(kRunnerService); bus.interface()->startService(kRunnerService);
QDBusInterface retryIface(kRunnerService, kRunnerPath, kRunnerInterface, bus); org::kde::ALaKarte::Runner1 retryIface(kRunnerService, kRunnerPath, bus);
if (!retryIface.isValid()) { if (!retryIface.isValid()) {
return false; return false;
} }
retryIface.setTimeout(2000); retryIface.setTimeout(2000);
const QDBusReply<QVariantMap> retryReply = retryIface.call(QStringLiteral("ResolveLaunch"), spec); QDBusPendingReply<QVariantMap> retryReply = retryIface.ResolveLaunch(spec);
if (!retryReply.isValid()) { retryReply.waitForFinished();
if (retryReply.isError()) {
return false; return false;
} }
out = unwrapVariantMap(retryReply.value()); out = unwrapVariantMap(retryReply.value());
@ -556,7 +560,7 @@ void GameLauncher::launchGame(Game *game)
// Always try daemon first — for all launch types // Always try daemon first — for all launch types
{ {
QDBusInterface iface(kGameCenterService, kGameCenterPath, kGameCenterInterface, QDBusConnection::sessionBus()); org::kde::GameCenter1 iface(kGameCenterService, kGameCenterPath, QDBusConnection::sessionBus());
QVariantMap launchSpec = { QVariantMap launchSpec = {
{QStringLiteral("command"), launchCommand}, {QStringLiteral("command"), launchCommand},
{QStringLiteral("gameId"), game->id()}, {QStringLiteral("gameId"), game->id()},
@ -595,8 +599,10 @@ void GameLauncher::launchGame(Game *game)
launchSpec.insert(QStringLiteral("workingDirectory"), workingDirectory); launchSpec.insert(QStringLiteral("workingDirectory"), workingDirectory);
} }
const QDBusReply<QString> reply = iface.call(QStringLiteral("Launch"), launchSpec); iface.setTimeout(5000);
if (reply.isValid() && !reply.value().isEmpty()) { QDBusPendingReply<QString> reply = iface.Launch(launchSpec);
reply.waitForFinished();
if (!reply.isError() && !reply.value().isEmpty()) {
m_daemonGameToSession.insert(game->id(), reply.value()); m_daemonGameToSession.insert(game->id(), reply.value());
m_daemonSessionToGame.insert(reply.value(), game->id()); m_daemonSessionToGame.insert(reply.value(), game->id());
game->setRunning(true); game->setRunning(true);
@ -610,7 +616,7 @@ void GameLauncher::launchGame(Game *game)
return; return;
} }
const QString launchError = reply.isValid() ? QString() : reply.error().message(); const QString launchError = reply.isError() ? reply.error().message() : QString();
// No fallback for non-URL commands — emit error // No fallback for non-URL commands — emit error
if (!launchError.isEmpty()) { if (!launchError.isEmpty()) {
@ -627,8 +633,8 @@ void GameLauncher::stopGame(Game *game)
return; return;
} }
QDBusInterface iface(kGameCenterService, kGameCenterPath, kGameCenterInterface, QDBusConnection::sessionBus()); org::kde::GameCenter1 iface(kGameCenterService, kGameCenterPath, QDBusConnection::sessionBus());
iface.call(QStringLiteral("StopByGameId"), game->id()); iface.StopByGameId(game->id());
} }
bool GameLauncher::isGameRunning(Game *game) const bool GameLauncher::isGameRunning(Game *game) const
@ -758,10 +764,12 @@ void GameLauncher::onDaemonLaunchFailed(const QVariantMap &error)
void GameLauncher::syncDaemonSessions() void GameLauncher::syncDaemonSessions()
{ {
QDBusInterface iface(kGameCenterService, kGameCenterPath, kGameCenterInterface, QDBusConnection::sessionBus()); org::kde::GameCenter1 iface(kGameCenterService, kGameCenterPath, QDBusConnection::sessionBus());
iface.setTimeout(2000);
const QDBusReply<QVariantList> reply = iface.call(QStringLiteral("ListSessions")); QDBusPendingReply<QVariantList> reply = iface.ListSessions();
if (!reply.isValid()) { reply.waitForFinished();
if (reply.isError()) {
return; return;
} }