Skip to content

Commit 3497831

Browse files
committed
Spectra - automatically searchfor and select a DevTools target
1 parent 20386cf commit 3497831

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

gui/spectra/tau5_spectra.cpp

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4005,15 +4005,61 @@ int main(int argc, char *argv[])
40054005
});
40064006

40074007
server.start();
4008-
4008+
40094009
debugLog("MCP server ready. Starting pre-emptive CDP connection...");
4010-
4011-
// Pre-emptively start the connection process to reduce first-request latency
4012-
QTimer::singleShot(500, [&bridge]() {
4010+
4011+
// Pre-emptively start the connection process and auto-select a target to reduce first-request latency
4012+
QTimer::singleShot(500, [&bridge, &cdpClient]() {
40134013
debugLog("Starting pre-emptive CDP connection attempt");
4014-
bridge.ensureConnected();
4014+
if (bridge.ensureConnected()) {
4015+
// Connection established, now try to auto-select a target
4016+
debugLog("CDP connected, attempting to auto-select target...");
4017+
4018+
QJsonArray targets = cdpClient->getAvailableTargets();
4019+
4020+
if (!targets.isEmpty()) {
4021+
// Try to find a target titled "Tau5" first
4022+
QString targetTitle;
4023+
for (const QJsonValue& value : targets) {
4024+
QJsonObject target = value.toObject();
4025+
if (target["type"].toString() == "page") {
4026+
QString title = target["title"].toString();
4027+
if (title == "Tau5" || title.contains("Tau5")) {
4028+
targetTitle = title;
4029+
break;
4030+
}
4031+
}
4032+
}
4033+
4034+
// If no Tau5 target found, use the first page target
4035+
if (targetTitle.isEmpty()) {
4036+
for (const QJsonValue& value : targets) {
4037+
QJsonObject target = value.toObject();
4038+
if (target["type"].toString() == "page") {
4039+
targetTitle = target["title"].toString();
4040+
break;
4041+
}
4042+
}
4043+
}
4044+
4045+
if (!targetTitle.isEmpty()) {
4046+
bool success = cdpClient->setTargetByTitle(targetTitle);
4047+
if (success) {
4048+
debugLog(QString("Auto-connected to target: %1").arg(targetTitle));
4049+
} else {
4050+
debugLog(QString("Failed to auto-connect to target: %1").arg(targetTitle));
4051+
}
4052+
} else {
4053+
debugLog("No suitable page targets found for auto-connect");
4054+
}
4055+
} else {
4056+
debugLog("No targets available for auto-connect");
4057+
}
4058+
} else {
4059+
debugLog("CDP connection failed, skipping auto-connect");
4060+
}
40154061
});
4016-
4062+
40174063
QObject::connect(cdpClient.get(), &CDPClient::connected, []() {
40184064
debugLog("Successfully connected to Chrome DevTools");
40194065
});

0 commit comments

Comments
 (0)