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

96 lines
2.3 KiB
JavaScript
Raw Normal View History

import SystemTray from 'resource:///com/github/Aylur/ags/service/systemtray.js';
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
2023-11-13 16:33:19 -05:00
import { Box, Icon, MenuItem, MenuBar, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
2023-09-11 19:57:21 -04:00
2023-11-16 00:48:50 -05:00
import Separator from '../../misc/separator.js';
const REVEAL_DURATION = 500;
const SPACING = 12;
const SysTrayItem = (item) => {
if (item.id === 'spotify-client') {
return;
}
return MenuItem({
child: Revealer({
transition: 'slide_right',
transitionDuration: REVEAL_DURATION,
child: Icon({
size: 24,
2023-11-13 16:33:19 -05:00
binds: [['icon', item, 'icon']],
}),
}),
submenu: item.menu,
2023-11-13 16:33:19 -05:00
binds: [['tooltipMarkup', item, 'tooltip-markup']],
});
};
2023-11-13 16:33:19 -05:00
const SysTray = () => MenuBar({
setup: (self) => {
2023-11-13 16:33:19 -05:00
self.items = new Map();
2023-10-18 11:53:49 -04:00
self.onAdded = (id) => {
2023-11-13 16:33:19 -05:00
const item = SystemTray.getItem(id);
if (self.items.has(id) || !item) {
2023-11-13 16:33:19 -05:00
return;
}
2023-11-13 16:33:19 -05:00
const w = SysTrayItem(item);
2023-11-13 16:33:19 -05:00
// Early return if item is in blocklist
if (!w) {
2023-11-13 16:33:19 -05:00
return;
}
2023-10-18 11:53:49 -04:00
2023-11-13 16:33:19 -05:00
self.items.set(id, w);
self.add(w);
self.show_all();
w.child.revealChild = true;
};
2023-10-18 11:53:49 -04:00
self.onRemoved = (id) => {
if (!self.items.has(id)) {
2023-11-13 16:33:19 -05:00
return;
}
2023-10-18 11:53:49 -04:00
2023-11-13 16:33:19 -05:00
self.items.get(id).child.revealChild = false;
timeout(REVEAL_DURATION, () => {
2023-11-13 16:33:19 -05:00
self.items.get(id).destroy();
self.items.delete(id);
});
};
},
connections: [
[SystemTray, (self, id) => self.onAdded(id), 'added'],
[SystemTray, (self, id) => self.onRemoved(id), 'removed'],
],
});
2023-10-18 11:53:49 -04:00
export default () => {
const systray = SysTray();
return Revealer({
transition: 'slide_right',
connections: [[SystemTray, (rev) => {
rev.revealChild = systray.get_children().length > 0;
}]],
child: Box({
children: [
Box({
className: 'sys-tray',
children: [systray],
}),
Separator(SPACING),
],
}),
});
};