2024-07-08 21:15:11 -04:00
|
|
|
import Tray from 'gi://AstalTray?version=0.1';
|
|
|
|
const SystemTray = Tray.Tray.get_default();
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-01-30 11:29:07 -05:00
|
|
|
const { timeout } = Utils;
|
|
|
|
const { Box, Icon, MenuItem, MenuBar, Revealer } = Widget;
|
2023-09-11 19:57:21 -04:00
|
|
|
|
2024-01-13 23:38:31 -05:00
|
|
|
import Separator from '../../misc/separator.ts';
|
2023-09-06 17:36:26 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const REVEAL_DURATION = 500;
|
|
|
|
const SPACING = 12;
|
|
|
|
|
2024-07-08 21:15:11 -04:00
|
|
|
/* Types */
|
|
|
|
// FIXME: get types from 'gi://AstalTray'
|
|
|
|
import type AstalTray from 'types/astal-tray/astaltray-0.1.d.ts';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
|
2024-07-08 21:15:11 -04:00
|
|
|
const SysTrayItem = (item: AstalTray.TrayItem) => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (item.id === 'spotify-client') {
|
2023-11-01 23:20:09 -04:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-01 23:20:09 -04:00
|
|
|
|
|
|
|
return MenuItem({
|
2024-07-08 21:15:11 -04:00
|
|
|
submenu: item.create_menu(),
|
2023-11-01 23:20:09 -04:00
|
|
|
child: Revealer({
|
|
|
|
transition: 'slide_right',
|
2023-12-18 18:00:30 -05:00
|
|
|
transition_duration: REVEAL_DURATION,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-07-08 21:15:11 -04:00
|
|
|
child: Icon({
|
|
|
|
size: 24,
|
|
|
|
icon: Utils.watch(
|
|
|
|
item.iconPixbuf || item.iconName || 'image-missing',
|
|
|
|
item,
|
|
|
|
() => item.iconPixbuf || item.iconName || 'image-missing',
|
|
|
|
),
|
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2024-07-08 21:15:11 -04:00
|
|
|
}).bind('tooltip_markup', item, 'tooltipMarkup');
|
2023-11-01 23:20:09 -04:00
|
|
|
};
|
2023-09-06 17:36:26 -04:00
|
|
|
|
2023-11-13 16:33:19 -05:00
|
|
|
const SysTray = () => MenuBar({
|
2024-01-13 11:15:08 -05:00
|
|
|
attribute: { items: new Map() },
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-12-18 18:00:30 -05:00
|
|
|
setup: (self) => {
|
2023-12-17 00:01:58 -05:00
|
|
|
self
|
2023-12-19 13:44:12 -05:00
|
|
|
.hook(SystemTray, (_, id) => {
|
2024-07-08 21:15:11 -04:00
|
|
|
if (!id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const item = SystemTray.get_item(id);
|
2023-12-19 13:44:12 -05:00
|
|
|
|
|
|
|
if (self.attribute.items.has(id) || !item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const w = SysTrayItem(item);
|
|
|
|
|
|
|
|
// Early return if item is in blocklist
|
|
|
|
if (!w) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.attribute.items.set(id, w);
|
2024-02-11 02:18:59 -05:00
|
|
|
self.add(w);
|
2023-12-19 13:44:12 -05:00
|
|
|
self.show_all();
|
2024-01-13 11:15:08 -05:00
|
|
|
|
2024-01-29 18:54:07 -05:00
|
|
|
w.child.reveal_child = true;
|
2024-07-08 21:15:11 -04:00
|
|
|
}, 'item_added')
|
2023-12-19 13:44:12 -05:00
|
|
|
|
|
|
|
.hook(SystemTray, (_, id) => {
|
2024-07-08 21:15:11 -04:00
|
|
|
if (!id || !self.attribute.items.has(id)) {
|
2023-12-19 13:44:12 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.attribute.items.get(id).child.reveal_child = false;
|
|
|
|
timeout(REVEAL_DURATION, () => {
|
|
|
|
self.attribute.items.get(id).destroy();
|
|
|
|
self.attribute.items.delete(id);
|
|
|
|
});
|
2024-07-08 21:15:11 -04:00
|
|
|
}, 'item_removed');
|
2023-11-13 16:33:19 -05:00
|
|
|
},
|
|
|
|
});
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export default () => {
|
|
|
|
const systray = SysTray();
|
|
|
|
|
|
|
|
return Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
|
|
|
|
child: Box({
|
|
|
|
children: [
|
|
|
|
Box({
|
2023-12-18 18:00:30 -05:00
|
|
|
class_name: 'sys-tray',
|
2023-11-21 01:29:46 -05:00
|
|
|
children: [systray],
|
|
|
|
}),
|
|
|
|
|
|
|
|
Separator(SPACING),
|
|
|
|
],
|
|
|
|
}),
|
2023-12-18 18:00:30 -05:00
|
|
|
}).hook(SystemTray, (self) => {
|
|
|
|
self.reveal_child = systray.get_children().length > 0;
|
2024-07-08 21:15:11 -04:00
|
|
|
}, 'item_added');
|
2023-11-21 01:29:46 -05:00
|
|
|
};
|