1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-06 13:38:28 -04:00

fix(Bluetooth): update codec selection and error handling

Fixes #2240
This commit is contained in:
purian23
2026-07-04 21:48:34 -04:00
parent 8f100960cf
commit c5c3105469
5 changed files with 138 additions and 119 deletions
+65
View File
@@ -14,6 +14,9 @@ Singleton {
readonly property bool available: adapter !== null
readonly property bool enabled: (adapter && adapter.enabled) ?? false
readonly property bool discovering: (adapter && adapter.discovering) ?? false
property bool pactlAvailable: false
property bool pactlChecked: false
property var pendingPactlActions: []
readonly property var devices: adapter ? adapter.devices : null
readonly property bool enhancedPairingAvailable: DMSService.dmsAvailable && DMSService.apiVersion >= 9 && DMSService.capabilities.includes("bluetooth")
readonly property bool connected: {
@@ -61,6 +64,23 @@ Singleton {
});
}
Component.onCompleted: {
detectPactlProcess.running = true;
}
function whenPactlChecked(action) {
if (pactlChecked) {
action();
return;
}
const actions = pendingPactlActions.slice();
actions.push(action);
pendingPactlActions = actions;
if (!detectPactlProcess.running)
detectPactlProcess.running = true;
}
function sortDevices(devices) {
return devices.sort((a, b) => {
const aName = a.name || a.deviceName || "";
@@ -305,6 +325,13 @@ Singleton {
if (!device || !device.connected || !isAudioDevice(device)) {
return;
}
if (!pactlChecked) {
whenPactlChecked(() => root.refreshDeviceCodec(device));
return;
}
if (!pactlAvailable) {
return;
}
const cardName = getCardName(device);
codecQueryProcess.cardName = cardName;
@@ -320,6 +347,14 @@ Singleton {
callback("");
return;
}
if (!pactlChecked) {
whenPactlChecked(() => root.getCurrentCodec(device, callback));
return;
}
if (!pactlAvailable) {
callback("");
return;
}
const cardName = getCardName(device);
codecQueryProcess.cardName = cardName;
@@ -335,6 +370,14 @@ Singleton {
callback([], "");
return;
}
if (!pactlChecked) {
whenPactlChecked(() => root.getAvailableCodecs(device, callback));
return;
}
if (!pactlAvailable) {
callback([], "");
return;
}
const cardName = getCardName(device);
codecFullQueryProcess.cardName = cardName;
@@ -350,6 +393,14 @@ Singleton {
callback(false, "Invalid device");
return;
}
if (!pactlChecked) {
whenPactlChecked(() => root.switchCodec(device, profileName, callback));
return;
}
if (!pactlAvailable) {
callback(false, I18n.tr("Codec switching is unavailable because pactl was not found"));
return;
}
const cardName = getCardName(device);
codecSwitchProcess.cardName = cardName;
@@ -358,6 +409,20 @@ Singleton {
codecSwitchProcess.running = true;
}
Process {
id: detectPactlProcess
running: false
command: ["sh", "-c", "command -v pactl"]
onExited: function (exitCode) {
root.pactlAvailable = (exitCode === 0);
root.pactlChecked = true;
const actions = root.pendingPactlActions.slice();
root.pendingPactlActions = [];
actions.forEach(action => action());
}
}
Process {
id: codecQueryProcess