feat(bt): update service to support interactive pairing process

This commit is contained in:
Turann_
2026-01-15 05:40:33 +03:00
parent 7ffd05bfdd
commit 9a9ac21833
+51 -3
View File
@@ -516,6 +516,48 @@ Singleton {
}
}
// Interaction state
property bool pinRequired: false
function submitPin(pin) {
if (pairingProcess.running) {
pairingProcess.write(pin + "\n");
root.pinRequired = false;
}
}
function cancelPairing() {
if (pairingProcess.running) {
pairingProcess.kill();
}
root.pinRequired = false;
}
// Interactive pairing process
Process {
id: pairingProcess
stdout: SplitParser {
onRead: data => {
var chunk = data;
if (chunk.indexOf("[PIN_REQ]") !== -1) {
root.pinRequired = true;
Logger.i("Bluetooth", "PIN required for pairing");
ToastService.showNotice(I18n.tr("common.bluetooth"), I18n.tr("bluetooth.panel.pin-required"), "lock");
}
}
}
stderr: StdioCollector {}
onExited: {
root.pinRequired = false;
Logger.i("Bluetooth", "Pairing process exited.");
// Restore discovery if we paused it
if (root._discoveryWasRunning) {
root.setScanActive(true, 0);
}
root._discoveryWasRunning = false;
}
}
// Pair using bluetoothctl which registers its own BlueZ agent internally.
function pairWithBluetoothctl(device) {
if (!device) {
@@ -528,6 +570,12 @@ Singleton {
}
Logger.i("Bluetooth", "pairWithBluetoothctl", addr);
// Stop any previous pairing attempt
if (pairingProcess.running) {
pairingProcess.kill();
}
root.pinRequired = false;
// Compute bounded waits from tunables
const pairWait = Math.max(5, Number(root.pairWaitSeconds) | 0);
@@ -539,10 +587,10 @@ Singleton {
const totalPauseMs = (pairWait * 1000) + (attempts * intervalSec * 1000) + 2000;
_pauseDiscoveryFor(totalPauseMs);
// Prefer external dev script for pairing/connecting; executed detached
const scriptPath = Quickshell.shellDir + "/Bin/bluetooth-connect.py";
// Use python3 explicitly
btExec(["python3", scriptPath, String(addr), String(pairWait), String(attempts), String(intervalSec)]);
pairingProcess.command = ["python3", scriptPath, String(addr), String(pairWait), String(attempts), String(intervalSec)];
pairingProcess.running = true;
}
// Helper to run bluetoothctl and scripts with consistent error logging