Files
noctalia-shell/Helpers/BluetoothScripts.js
T
danny ba45c67d93 Add Bluetooth RSSI polling (Experimental) and CLI-based pairing helpers with code cleanup and restructurization for better maintainability
- 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.).
2026-01-02 03:09:16 +01:00

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
`;
};