nixos-configs/devices/wim/config/ags/js/bar/buttons/network.js

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-12-05 09:46:27 -05:00
import Network from 'resource:///com/github/Aylur/ags/service/network.js';
import { Label, Box, EventBox, Icon, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
import Separator from '../../misc/separator.js';
2023-12-18 18:00:30 -05:00
const SPACING = 5;
2023-12-05 09:46:27 -05:00
2023-12-18 18:00:30 -05:00
export default () => {
const indicator = Icon().hook(Network, (self) => {
if (Network.wifi.internet === 'connected' ||
Network.wifi.internet === 'connecting') {
self.icon = Network.wifi.icon_name;
}
else if (Network.wired.internet === 'connected' ||
Network.wired.internet === 'connecting') {
self.icon = Network.wired.icon_name;
}
else {
self.icon = Network.wifi.icon_name;
}
});
2023-12-05 09:46:27 -05:00
2023-12-18 18:00:30 -05:00
const label = Label().hook(Network, (self) => {
if (Network.wifi.internet === 'connected' ||
Network.wifi.internet === 'connecting') {
self.label = Network.wifi.ssid || 'Unknown';
2023-12-18 18:00:30 -05:00
}
else if (Network.wired.internet === 'connected' ||
Network.wired.internet === 'connecting') {
self.label = 'Connected';
}
else {
self.label = 'Disconnected';
}
});
2023-12-05 09:46:27 -05:00
2023-12-18 18:00:30 -05:00
const hoverRevLabel = Revealer({
2023-12-05 09:46:27 -05:00
transition: 'slide_right',
child: Box({
children: [
Separator(SPACING),
2023-12-18 18:00:30 -05:00
label,
2023-12-05 09:46:27 -05:00
],
}),
});
const widget = EventBox({
2023-12-18 18:00:30 -05:00
on_hover: () => {
hoverRevLabel.reveal_child = true;
2023-12-05 09:46:27 -05:00
},
2023-12-18 18:00:30 -05:00
on_hover_lost: () => {
hoverRevLabel.reveal_child = false;
2023-12-05 09:46:27 -05:00
},
2023-12-18 18:00:30 -05:00
2023-12-05 09:46:27 -05:00
child: Box({
2023-12-18 18:00:30 -05:00
class_name: 'network',
2023-12-05 09:46:27 -05:00
children: [
2023-12-18 18:00:30 -05:00
indicator,
2023-12-05 09:46:27 -05:00
2023-12-18 18:00:30 -05:00
hoverRevLabel,
2023-12-05 09:46:27 -05:00
],
}),
});
return widget;
};