nixos-configs/nixosModules/ags/config/widgets/bar/items/network.tsx

64 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-11-03 23:35:53 -05:00
import { bind, Variable } from 'astal';
import { Gtk } from 'astal/gtk3';
import AstalNetwork from 'gi://AstalNetwork';
export default () => {
const network = AstalNetwork.get_default();
2024-11-03 23:35:53 -05:00
const Hovered = Variable(false);
2024-11-03 23:35:53 -05:00
return (
<button
className="bar-item network"
cursor="pointer"
onEnterNotifyEvent={() => Hovered.set(true)}
onLeaveNotifyEvent={() => Hovered.set(false)}
2024-11-03 23:35:53 -05:00
>
{bind(network, 'primary').as((primary) => {
2024-11-03 23:35:53 -05:00
if (primary === AstalNetwork.Primary.UNKNOWN) {
return (<icon icon="network-wireless-signal-none-symbolic" />);
}
else if (primary === AstalNetwork.Primary.WIFI) {
const Wifi = network.get_wifi();
2024-11-03 23:35:53 -05:00
if (!Wifi) { return; }
return (
<box>
{/* Make sure the AP is there before binding to it */}
{bind(Wifi, 'accessPoints').as((aps) => {
if (aps.length === 0) { return; }
return (
<>
<icon icon={bind(Wifi, 'iconName')} />
<revealer
revealChild={bind(Hovered)}
transitionType={Gtk.RevealerTransitionType.SLIDE_LEFT}
>
{bind(Wifi, 'activeAccessPoint').as((ap) => ap && (
<label label={bind(ap, 'ssid')} />
))}
</revealer>
</>
);
})}
2024-11-03 23:35:53 -05:00
</box>
);
}
else {
const Wired = network.get_wired();
2024-11-03 23:35:53 -05:00
if (!Wired) { return; }
return (<icon icon={bind(Wired, 'iconName')} />);
}
})}
</button>
);
};