import { bind } from 'astal'; import { Gtk } from 'astal/gtk3'; import AstalBluetooth from 'gi://AstalBluetooth'; import { ToggleButton } from '../misc/subclasses'; import Separator from '../misc/separator'; import DeviceWidget from './device'; export default () => { const bluetooth = AstalBluetooth.get_default(); const deviceList = ( { self.children = bluetooth.devices .filter((dev) => dev.name) .map((dev) => ); self.hook(bluetooth, 'device-added', (_, dev) => { if (dev.name) { self.add(); } }); self.hook(bluetooth, 'device-removed', (_, dev) => { const children = self.children as DeviceWidget[]; const devWidget = children.find((ch) => ch.dev === dev); if (devWidget) { devWidget.revealChild = false; setTimeout(() => { devWidget.destroy(); }, devWidget.transitionDuration + 100); } }); }} > ); return ( { self.connect('notify::active', () => { bluetooth.adapter?.set_powered(self.active); }); }} /> { self.toggleClassName('active', self.active); if (self.active) { bluetooth.adapter?.start_discovery(); } else { bluetooth.adapter?.stop_discovery(); } }} > {deviceList} ); };