2023-10-31 08:32:40 -04:00
|
|
|
import SystemTray from 'resource:///com/github/Aylur/ags/service/systemtray.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-31 08:32:40 -04:00
|
|
|
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';
|
2023-09-06 17:36:26 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const REVEAL_DURATION = 500;
|
|
|
|
const SPACING = 12;
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-12-18 18:00:30 -05:00
|
|
|
/** @param {import('types/service/systemtray').TrayItem} item */
|
2023-11-21 01:29:46 -05:00
|
|
|
const SysTrayItem = (item) => {
|
|
|
|
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({
|
2023-12-18 18:00:30 -05:00
|
|
|
// @ts-expect-error
|
|
|
|
submenu: item.menu,
|
|
|
|
tooltip_markup: item.bind('tooltip_markup'),
|
|
|
|
|
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
|
|
|
|
2023-11-01 23:20:09 -04:00
|
|
|
child: Icon({
|
|
|
|
size: 24,
|
2023-12-19 13:44:12 -05:00
|
|
|
// @ts-expect-error
|
2023-12-18 18:00:30 -05:00
|
|
|
icon: item.bind('icon'),
|
2023-11-01 23:20:09 -04:00
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
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({
|
2023-12-18 18:00:30 -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) => {
|
|
|
|
const item = SystemTray.getItem(id);
|
|
|
|
|
|
|
|
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);
|
|
|
|
self.child = w;
|
|
|
|
self.show_all();
|
|
|
|
// @ts-expect-error
|
|
|
|
w.child.reveal_child = true;
|
|
|
|
}, 'added')
|
|
|
|
|
|
|
|
.hook(SystemTray, (_, id) => {
|
|
|
|
if (!self.attribute.items.has(id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.attribute.items.get(id).child.reveal_child = false;
|
|
|
|
timeout(REVEAL_DURATION, () => {
|
|
|
|
self.attribute.items.get(id).destroy();
|
|
|
|
self.attribute.items.delete(id);
|
|
|
|
});
|
|
|
|
}, '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) => {
|
2023-12-19 13:44:12 -05:00
|
|
|
// @ts-expect-error
|
2023-12-18 18:00:30 -05:00
|
|
|
self.reveal_child = systray.get_children().length > 0;
|
2023-11-21 01:29:46 -05:00
|
|
|
});
|
|
|
|
};
|