import { bind, Variable } from 'astal'; import { Gtk } from 'astal/gtk3'; import AstalNetwork from 'gi://AstalNetwork'; import { ToggleButton } from '../misc/subclasses'; import Separator from '../misc/separator'; import AccessPointWidget from './access-point'; export default () => { const wifi = AstalNetwork.get_default().get_wifi(); if (!wifi) { throw new Error('Could not find wifi device.'); } const IsRefreshing = Variable(false); const AccessPoints = Variable(wifi.get_access_points()); wifi.connect('notify::access-points', () => { if (IsRefreshing.get()) { AccessPoints.set(wifi.get_access_points()); } }); IsRefreshing.subscribe(() => { if (IsRefreshing.get()) { AccessPoints.set(wifi.get_access_points()); } }); const apList = ( {bind(AccessPoints).as(() => { const joined = new Map(); AccessPoints.get() .filter((ap) => ap.get_ssid()) .sort((apA, apB) => { const sort = apB.get_strength() - apA.get_strength(); return sort !== 0 ? sort : apA.get_ssid()!.localeCompare(apB.get_ssid()!); }) .forEach((ap) => { const arr = joined.get(ap.get_ssid()!); if (arr) { arr.push(ap); } else { joined.set(ap.get_ssid()!, [ap]); } }); return [...joined.values()].map((aps) => ); })} ); return ( { self.connect('notify::active', () => { wifi.set_enabled(self.active); }); }} /> { self.toggleClassName('active', self.active); IsRefreshing.set(self.active); }} > {apList} ); };