mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
feat(bt): update service to support interactive pairing process
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user