2024-10-15 20:01:20 -04:00
|
|
|
import { App, Gdk, Gtk, Widget } from 'astal/gtk3';
|
|
|
|
import { bind, idle } from 'astal';
|
2024-10-12 04:03:22 -04:00
|
|
|
|
|
|
|
import AstalTray from 'gi://AstalTray';
|
|
|
|
|
|
|
|
|
|
|
|
const SKIP_ITEMS = ['.spotify-wrapped'];
|
|
|
|
|
|
|
|
const TrayItem = (item: AstalTray.TrayItem) => {
|
|
|
|
if (item.iconThemePath) {
|
|
|
|
App.add_icons(item.iconThemePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
const menu = item.create_menu();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<revealer
|
|
|
|
transitionType={Gtk.RevealerTransitionType.SLIDE_RIGHT}
|
|
|
|
revealChild={false}
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
className="tray-item"
|
|
|
|
cursor="pointer"
|
|
|
|
tooltipMarkup={bind(item, 'tooltipMarkup')}
|
|
|
|
onDestroy={() => menu?.destroy()}
|
|
|
|
onClickRelease={(self) => {
|
|
|
|
menu?.popup_at_widget(self, Gdk.Gravity.SOUTH, Gdk.Gravity.NORTH, null);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<icon gIcon={bind(item, 'gicon')} />
|
|
|
|
</button>
|
|
|
|
</revealer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default () => {
|
2024-11-20 23:38:41 -05:00
|
|
|
const tray = AstalTray.get_default();
|
|
|
|
|
2024-10-12 04:03:22 -04:00
|
|
|
const itemMap = new Map<string, Widget.Revealer>();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<box
|
|
|
|
className="bar-item system-tray"
|
2024-11-20 23:38:41 -05:00
|
|
|
visible={bind(tray, 'items').as((items) => items.length !== 0)}
|
2024-10-12 04:03:22 -04:00
|
|
|
setup={(self) => {
|
|
|
|
self
|
2024-11-20 23:38:41 -05:00
|
|
|
.hook(tray, 'item-added', (_, item: string) => {
|
|
|
|
if (itemMap.has(item) || SKIP_ITEMS.includes(tray.get_item(item).title)) {
|
2024-10-12 04:03:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-20 23:38:41 -05:00
|
|
|
const widget = TrayItem(tray.get_item(item)) as Widget.Revealer;
|
2024-10-12 04:03:22 -04:00
|
|
|
|
|
|
|
itemMap.set(item, widget);
|
|
|
|
|
|
|
|
self.add(widget);
|
|
|
|
|
|
|
|
idle(() => {
|
|
|
|
widget.set_reveal_child(true);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
2024-11-20 23:38:41 -05:00
|
|
|
.hook(tray, 'item-removed', (_, item: string) => {
|
2024-10-12 04:03:22 -04:00
|
|
|
if (!itemMap.has(item)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const widget = itemMap.get(item);
|
|
|
|
|
|
|
|
widget?.set_reveal_child(false);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
widget?.destroy();
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|