2024-11-03 23:35:53 -05:00
|
|
|
import { bind, Variable } from 'astal';
|
2024-12-19 17:46:57 -05:00
|
|
|
import { App, Gtk } from 'astal/gtk3';
|
2024-11-03 23:35:53 -05:00
|
|
|
|
|
|
|
import AstalNetwork from 'gi://AstalNetwork';
|
|
|
|
|
2024-12-19 17:46:57 -05:00
|
|
|
/* Types */
|
|
|
|
import PopupWindow from '../../misc/popup-window';
|
|
|
|
|
2024-11-03 23:35:53 -05:00
|
|
|
|
|
|
|
export default () => {
|
2024-11-20 12:29:06 -05:00
|
|
|
const network = AstalNetwork.get_default();
|
2024-11-03 23:35:53 -05:00
|
|
|
|
2024-11-20 23:38:41 -05:00
|
|
|
const Hovered = Variable(false);
|
|
|
|
|
2024-11-03 23:35:53 -05:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
className="bar-item network"
|
|
|
|
cursor="pointer"
|
|
|
|
|
2024-11-24 17:16:22 -05:00
|
|
|
onHover={() => Hovered.set(true)}
|
|
|
|
onHoverLost={() => Hovered.set(false)}
|
2024-12-19 17:46:57 -05:00
|
|
|
|
|
|
|
onButtonReleaseEvent={(self) => {
|
|
|
|
const win = App.get_window('win-network') as PopupWindow;
|
|
|
|
|
|
|
|
win.set_x_pos(
|
|
|
|
self.get_allocation(),
|
|
|
|
'right',
|
|
|
|
);
|
|
|
|
|
|
|
|
win.visible = !win.visible;
|
|
|
|
}}
|
2024-11-03 23:35:53 -05:00
|
|
|
>
|
2024-11-20 12:29:06 -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) {
|
2024-11-20 12:29:06 -05:00
|
|
|
const Wifi = network.get_wifi();
|
2024-11-03 23:35:53 -05:00
|
|
|
|
2024-11-24 17:16:22 -05:00
|
|
|
if (!Wifi || Wifi.accessPoints.length === 0) { return; }
|
2024-11-03 23:35:53 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<box>
|
2024-11-24 17:16:22 -05:00
|
|
|
<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 {
|
2024-11-20 12:29:06 -05:00
|
|
|
const Wired = network.get_wired();
|
2024-11-03 23:35:53 -05:00
|
|
|
|
|
|
|
if (!Wired) { return; }
|
|
|
|
|
|
|
|
return (<icon icon={bind(Wired, 'iconName')} />);
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
};
|