2023-10-31 08:32:40 -04:00
|
|
|
import SystemTray from 'resource:///com/github/Aylur/ags/service/systemtray.js';
|
|
|
|
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
|
|
|
import { Box, Icon, MenuItem, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
|
|
|
import Gtk from 'gi://Gtk';
|
2023-09-11 19:57:21 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
import Separator from '../misc/separator.js';
|
2023-09-06 17:36:26 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-11-01 23:20:09 -04:00
|
|
|
const SysTrayItem = item => {
|
|
|
|
if (item.id === 'spotify-client')
|
|
|
|
return;
|
|
|
|
|
|
|
|
return MenuItem({
|
|
|
|
child: Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
child: Icon({
|
|
|
|
size: 24,
|
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-11-01 23:20:09 -04:00
|
|
|
submenu: item.menu,
|
|
|
|
connections: [[item, btn => {
|
|
|
|
btn.child.child.icon = item.icon;
|
|
|
|
btn.tooltipMarkup = item.tooltipMarkup;
|
|
|
|
}]],
|
|
|
|
});
|
|
|
|
};
|
2023-09-06 17:36:26 -04:00
|
|
|
|
2023-10-18 11:53:49 -04:00
|
|
|
const SysTray = () => {
|
2023-10-20 23:11:21 -04:00
|
|
|
const widget = Gtk.MenuBar.new();
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
// Properties
|
|
|
|
widget._items = new Map();
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
widget._onAdded = id => {
|
|
|
|
const item = SystemTray.getItem(id);
|
|
|
|
if (widget._items.has(id) || !item)
|
|
|
|
return;
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
const w = SysTrayItem(item);
|
2023-11-01 23:20:09 -04:00
|
|
|
// Early return if item is in blocklist
|
|
|
|
if (!w)
|
|
|
|
return;
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
widget._items.set(id, w);
|
|
|
|
widget.add(w);
|
|
|
|
widget.show_all();
|
|
|
|
w.child.revealChild = true;
|
|
|
|
};
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
widget._onRemoved = id => {
|
|
|
|
if (!widget._items.has(id))
|
|
|
|
return;
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
widget._items.get(id).child.revealChild = false;
|
2023-10-31 08:32:40 -04:00
|
|
|
timeout(400, () => {
|
2023-10-20 23:11:21 -04:00
|
|
|
widget._items.get(id).destroy();
|
|
|
|
widget._items.delete(id);
|
|
|
|
});
|
|
|
|
};
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
// Connections
|
|
|
|
SystemTray.connect('added', (_, id) => widget._onAdded(id));
|
|
|
|
SystemTray.connect('removed', (_, id) => widget._onRemoved(id));
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
return widget;
|
|
|
|
};
|
2023-10-18 11:53:49 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default () => Revealer({
|
2023-10-20 23:11:21 -04:00
|
|
|
transition: 'slide_right',
|
|
|
|
connections: [[SystemTray, rev => {
|
|
|
|
rev.revealChild = rev.child.children[0].get_children().length > 0;
|
|
|
|
}]],
|
|
|
|
child: Box({
|
2023-10-04 13:35:20 -04:00
|
|
|
children: [
|
2023-10-20 23:11:21 -04:00
|
|
|
Box({
|
|
|
|
className: 'sys-tray',
|
|
|
|
children: [
|
|
|
|
SysTray(),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
Separator(12),
|
2023-09-26 08:57:32 -04:00
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-09-06 17:36:26 -04:00
|
|
|
});
|