nixos-configs/nixosModules/ags-v2/config/widgets/bar/items/network.tsx
matt1432 99ffdeac4c
All checks were successful
Discord / discord commits (push) Has been skipped
feat(agsV2): add some more bar items
2024-11-03 23:35:53 -05:00

53 lines
1.7 KiB
TypeScript

import { bind, Variable } from 'astal';
import { Gtk } from 'astal/gtk3';
import AstalNetwork from 'gi://AstalNetwork';
const Network = AstalNetwork.get_default();
export default () => {
const Hovered = Variable(false);
return (
<button
className="bar-item network"
cursor="pointer"
onHover={() => Hovered.set(true)}
onHoverLost={() => Hovered.set(false)}
>
{bind(Network, 'primary').as((primary) => {
if (primary === AstalNetwork.Primary.UNKNOWN) {
return (<icon icon="network-wireless-signal-none-symbolic" />);
}
else if (primary === AstalNetwork.Primary.WIFI) {
const Wifi = Network.get_wifi();
if (!Wifi) { return; }
return (
<box>
<icon icon={bind(Wifi, 'iconName')} />
<revealer
revealChild={bind(Hovered)}
transitionType={Gtk.RevealerTransitionType.SLIDE_LEFT}
>
{bind(Wifi, 'activeAccessPoint').as((ap) => (
<label label={bind(ap, 'ssid')} />
))}
</revealer>
</box>
);
}
else {
const Wired = Network.get_wired();
if (!Wired) { return; }
return (<icon icon={bind(Wired, 'iconName')} />);
}
})}
</button>
);
};