mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
ba45c67d93
- Introduced Bluetooth RSSI polling using `bluetoothctl` for connected devices with interval configuration. - Added reusable helpers for CLI-based device pairing and connection. - Enhanced Bluetooth panel with an opt-in toggle for RSSI polling. - Updated settings and defaults for RSSI polling configuration. - Refactored Bluetooth utilities for standardized device handling (icons, deduplication, signal parsing, etc.).
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
.pragma library
|
|
|
|
var pairAndConnectScript = (addr, pairWaitSeconds, attempts, intervalSec) => {
|
|
// Produces a shell script that pairs, trusts and attempts to connect repeatedly.
|
|
return `
|
|
addr='${addr}'
|
|
{
|
|
echo 'agent KeyboardDisplay'
|
|
echo 'default-agent'
|
|
echo 'power on'
|
|
echo "pair $addr"
|
|
# Give time for potential confirmation prompt; send 'yes' optimistically (no-op if not needed)
|
|
sleep 1
|
|
echo 'yes'
|
|
# Mark device trusted
|
|
echo "trust $addr"
|
|
# Attempt multiple connects within the session
|
|
for i in $(seq 1 ${attempts}); do
|
|
echo "connect $addr"
|
|
sleep ${intervalSec}
|
|
done
|
|
echo 'quit'
|
|
} | bluetoothctl &
|
|
|
|
# Wait up to ${pairWaitSeconds}s for pairing to complete
|
|
for i in $(seq 1 ${pairWaitSeconds}); do
|
|
if bluetoothctl info "$addr" | grep -q 'Paired: yes'; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# Check connection state for ~${attempts * intervalSec}s total
|
|
for i in $(seq 1 ${attempts}); do
|
|
if bluetoothctl info "$addr" | grep -q 'Connected: yes'; then
|
|
exit 0
|
|
fi
|
|
sleep ${intervalSec}
|
|
done
|
|
exit 1
|
|
`;
|
|
};
|