@domicile-desktop/system-bluetooth
v0.0.0-alpha-9a2cb3bbe5b4
Published
BlueZ for a Domicile shell: whether each adapter is powered and which devices are connected, kept current, and turning adapters on and off.
Readme
@domicile-desktop/system-bluetooth
BlueZ for a Domicile shell: each adapter and whether it is powered or
scanning, the devices it knows, and the requests that change them. Built on
@domicile-desktop/sdk/system.
Usage
import { system } from "@domicile-desktop/sdk/system";
import { setPowered, watchBluetooth } from "@domicile-desktop/system-bluetooth/bluetooth";
const host = system(domicile);
const stop = watchBluetooth(host, (bluetooth) => {
bluetooth.match({
Err: () => hide(),
Ok: ({ adapters, devices }) => show(adapters, devices),
});
});
await setPowered(host, "/org/bluez/hci0", false);- Reads
GetManagedObjectsonce, then again when an object comes or goes or one of these changes: an adapter'sPoweredorDiscovering, a device'sAlias,Name,ConnectedorPaired, or its battery'sPercentage. devicesholds paired devices and, from a scan, those with a name. Each hasbattery(0 through 100) fromorg.bluez.Battery1, orundefinedwhen it reports none.- Requests:
setPowered,startDiscovery,stopDiscovery,connect,disconnect,pair(then trusts the device) andforget. pairregisters no agent, so only devices that need no code pair.- An
Erris a D-Bus failure, such as BlueZ not running or an adapter blocked by rfkill. - A bug or an unexpected reply shape throws, logged to the console.
- Lock:
watchBluetoothworks while the desktop is locked, so a lock screen can show Bluetooth. Every request fails withlocked(LOCK.md).
Test
bun run turbo test --filter @domicile-desktop/system-bluetoothTests replay D-Bus replies, in the compositor's JSON, through an injected
System.
