Fix 2: Add displayIndex validation, specific TODO comment, and consolidate platform blocks

This commit is contained in:
Zac Gaetano 2026-05-06 20:39:10 -04:00
parent ce20ac7d8a
commit ef91b5385d

View file

@ -107,8 +107,6 @@ void DragonRelayBackend::streamHost(const QString &ip, const QString &app, int d
// Delegate to moonlight-qt's existing stream launch mechanism.
// The standard Moonlight PC model uses ComputerManager; we invoke it
// via a QProcess for now so we don't have to patch PC discovery internals.
// TODO: wire directly into Moonlight's ComputerManager once the fork is
// more deeply integrated.
qDebug() << "DragonRelayBackend::streamHost called with ip=" << ip
<< "app=" << app << "displayIndex=" << displayIndex;
@ -119,11 +117,6 @@ void DragonRelayBackend::streamHost(const QString &ip, const QString &app, int d
ip,
app
};
// TODO: map displayIndex to Moonlight --display flag or similar
// For now, log displayIndex and pass without flag
if (displayIndex > 0) {
qDebug() << "Display index" << displayIndex << "requested (Moonlight --display flag TODO)";
}
QProcess::startDetached(QStringLiteral("moonlight"), args);
#elif defined(Q_OS_MACOS)
QStringList args{
@ -131,10 +124,6 @@ void DragonRelayBackend::streamHost(const QString &ip, const QString &app, int d
ip,
app
};
// TODO: map displayIndex to Moonlight --display flag or similar
if (displayIndex > 0) {
qDebug() << "Display index" << displayIndex << "requested (Moonlight --display flag TODO)";
}
QProcess::startDetached(QStringLiteral("moonlight"), args);
#else
QStringList args{
@ -142,12 +131,16 @@ void DragonRelayBackend::streamHost(const QString &ip, const QString &app, int d
ip,
app
};
// TODO: map displayIndex to Moonlight --display flag or similar
if (displayIndex > 0) {
qDebug() << "Display index" << displayIndex << "requested (Moonlight --display flag TODO)";
}
QProcess::startDetached(QStringLiteral("moonlight"), args);
#endif
// TODO: Pass displayIndex to Moonlight stream command via the --display or
// --monitor flag. moonlight-qt uses NvHTTP::launchApp() with a "display"
// parameter. See app/streaming/session.cpp launchSession() for where
// display selection hooks should be added.
if (displayIndex > 0) {
qDebug() << " display index:" << displayIndex << "(Moonlight --display wiring pending)";
}
}
// ── displaysForHost ───────────────────────────────────────────────────────────
@ -160,6 +153,15 @@ QVariantList DragonRelayBackend::displaysForHost(const QString &hostIP) const {
void DragonRelayBackend::streamHostDisplay(const QString &hostIP, int displayIndex) {
qDebug() << "Streaming host" << hostIP << "display index" << displayIndex;
// Add displayIndex validation near the top of streamHost()
const QVariantList displays = displaysForHost(hostIP);
if (displayIndex < 0 || (!displays.isEmpty() && displayIndex >= displays.size())) {
qWarning() << "DragonRelayBackend: displayIndex" << displayIndex
<< "out of bounds for host" << hostIP << "(has" << displays.size() << "displays)";
displayIndex = 0; // fall back to primary
}
// Pass displayIndex to streamHost
streamHost(hostIP, QStringLiteral("Desktop"), displayIndex);
}