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