nixos-configs/modules/ags/config/widgets/bar/items/network.tsx
matt1432 6bc32a8d8e
All checks were successful
Discord / discord commits (push) Has been skipped
feat(ags): add wifi widget
2024-12-19 17:46:57 -05:00

68 lines
2.1 KiB
TypeScript

import { bind, Variable } from 'astal';
import { App, Gtk } from 'astal/gtk3';
import AstalNetwork from 'gi://AstalNetwork';
/* Types */
import PopupWindow from '../../misc/popup-window';
export default () => {
const network = AstalNetwork.get_default();
const Hovered = Variable(false);
return (
<button
className="bar-item network"
cursor="pointer"
onHover={() => Hovered.set(true)}
onHoverLost={() => Hovered.set(false)}
onButtonReleaseEvent={(self) => {
const win = App.get_window('win-network') as PopupWindow;
win.set_x_pos(
self.get_allocation(),
'right',
);
win.visible = !win.visible;
}}
>
{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 || Wifi.accessPoints.length === 0) { return; }
return (
<box>
<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>
</box>
);
}
else {
const Wired = network.get_wired();
if (!Wired) { return; }
return (<icon icon={bind(Wired, 'iconName')} />);
}
})}
</button>
);
};