Skip to content

Commit adac00e

Browse files
committed
WIP
1 parent 3b62d6b commit adac00e

1 file changed

Lines changed: 23 additions & 28 deletions

File tree

linux/mediacontroller.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -260,45 +260,40 @@ QString MediaController::getAudioDeviceName()
260260
{
261261
if (connectedDeviceMacAddress.isEmpty()) { return QString(); }
262262

263-
// Use a cleaner MAC address format for PulseAudio matching
263+
// Set up QProcess to run pactl directly
264264
QProcess process;
265-
process.start("pactl", QStringList() << "list" << "sinks");
266-
process.waitForFinished();
267-
268-
QString output = process.readAllStandardOutput();
269-
if (output.isEmpty())
265+
process.start("pactl", QStringList() << "list" << "sinks" << "short");
266+
if (!process.waitForFinished(3000)) // Timeout after 3 seconds
270267
{
271-
QProcess process;
272-
process.start("pactl", QStringList() << "list" << "sinks");
273-
process.waitForFinished();
274-
output = process.readAllStandardOutput();
275-
276-
if (output.isEmpty())
277-
{
278-
LOG_ERROR("Failed to get PulseAudio and PipeWire sink list");
279-
return QString();
280-
}
268+
LOG_ERROR("pactl command failed or timed out: " << process.errorString());
269+
return QString();
281270
}
282271

283-
QStringList lines = output.split("\n");
272+
// Check for execution errors
273+
if (process.exitCode() != 0)
274+
{
275+
LOG_ERROR("pactl exited with error code: " << process.exitCode());
276+
return QString();
277+
}
284278

285-
QString currentSinkName;
286-
bool foundDevice = false;
279+
// Read and parse the command output
280+
QString output = process.readAllStandardOutput();
281+
QStringList lines = output.split("\n", Qt::SkipEmptyParts);
287282

283+
// Iterate through each line to find a matching Bluetooth sink
288284
for (const QString &line : lines)
289285
{
290-
if (line.contains("device.name"))
291-
{
292-
currentSinkName = line.mid(line.indexOf(u'"') + 1).trimmed().removeLast();
293-
}
286+
QStringList fields = line.split("\t", Qt::SkipEmptyParts);
287+
if (fields.size() < 2) { continue; }
294288

295-
// Look for Bluetooth MAC address in various formats
296-
if (currentSinkName.contains(connectedDeviceMacAddress, Qt::CaseInsensitive))
289+
QString sinkName = fields[1].trimmed();
290+
if (sinkName.startsWith("bluez") && sinkName.contains(connectedDeviceMacAddress))
297291
{
298-
foundDevice = true;
299-
return currentSinkName;
292+
return sinkName;
300293
}
301294
}
302295

296+
// No matching sink found
297+
LOG_ERROR("No matching Bluetooth sink found for MAC address: " << connectedDeviceMacAddress);
303298
return QString();
304-
}
299+
}

0 commit comments

Comments
 (0)