fix(ags): prevent activeAccessPoint from being null
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-11-20 12:29:06 -05:00
parent 0af7f8b1e3
commit c648667ef3

View file

@ -2,11 +2,12 @@ import { bind, Variable } from 'astal';
import { Gtk } from 'astal/gtk3'; import { Gtk } from 'astal/gtk3';
import AstalNetwork from 'gi://AstalNetwork'; import AstalNetwork from 'gi://AstalNetwork';
const Network = AstalNetwork.get_default();
export default () => { export default () => {
const Hovered = Variable(false); const Hovered = Variable(false);
// TODO: do this everywhere else
const network = AstalNetwork.get_default();
return ( return (
<button <button
@ -16,32 +17,37 @@ export default () => {
onHover={() => Hovered.set(true)} onHover={() => Hovered.set(true)}
onHoverLost={() => Hovered.set(false)} onHoverLost={() => Hovered.set(false)}
> >
{bind(Network, 'primary').as((primary) => { {bind(network, 'primary').as((primary) => {
if (primary === AstalNetwork.Primary.UNKNOWN) { if (primary === AstalNetwork.Primary.UNKNOWN) {
return (<icon icon="network-wireless-signal-none-symbolic" />); return (<icon icon="network-wireless-signal-none-symbolic" />);
} }
else if (primary === AstalNetwork.Primary.WIFI) { else if (primary === AstalNetwork.Primary.WIFI) {
const Wifi = Network.get_wifi(); const Wifi = network.get_wifi();
if (!Wifi) { return; } if (!Wifi) { return; }
return ( return (
<box> <box>
{/* Make sure the AP is there before binding to it */}
{bind(Wifi, 'accessPoints').as((aps) => aps.length !== 0 && (
<>
<icon icon={bind(Wifi, 'iconName')} /> <icon icon={bind(Wifi, 'iconName')} />
<revealer <revealer
revealChild={bind(Hovered)} revealChild={bind(Hovered)}
transitionType={Gtk.RevealerTransitionType.SLIDE_LEFT} transitionType={Gtk.RevealerTransitionType.SLIDE_LEFT}
> >
{bind(Wifi, 'activeAccessPoint').as((ap) => ( {bind(Wifi, 'activeAccessPoint').as((ap) => ap && (
<label label={bind(ap, 'ssid')} /> <label label={bind(ap, 'ssid')} />
))} ))}
</revealer> </revealer>
</>
))}
</box> </box>
); );
} }
else { else {
const Wired = Network.get_wired(); const Wired = network.get_wired();
if (!Wired) { return; } if (!Wired) { return; }