import { bind, idle } from 'astal'; import { Gtk, Widget } from 'astal/gtk3'; import { register } from 'astal/gobject'; import AstalBluetooth from 'gi://AstalBluetooth'; import Separator from '../misc/separator'; /* Types */ interface DevToggleProps { label: string prop: keyof AstalBluetooth.Device onToggle: (active: boolean) => void } @register() export default class DeviceWidget extends Widget.Revealer { readonly dev: AstalBluetooth.Device; constructor({ dev }: { dev: AstalBluetooth.Device }) { const bluetooth = AstalBluetooth.get_default(); const DevToggle = ({ label, prop, onToggle }: DevToggleProps) => ( ); const rev = ( { if (active) { dev.connect_device(); } else { dev.disconnect_device(); } }} /> { dev.set_trusted(active); }} /> { if (active) { dev.pair(); } else { bluetooth.adapter.remove_device(dev); } }} /> { dev.set_blocked(active); }} /> ) as Widget.Revealer; const button = ( ); super({ revealChild: false, transitionType: Gtk.RevealerTransitionType.SLIDE_DOWN, child: ( {button} {rev} ), }); this.dev = dev; this.connect('realize', () => idle(() => { this.revealChild = true; })); }; };