2024-10-22 13:09:39 -04:00
|
|
|
import AstalNotifd from 'gi://AstalNotifd';
|
2024-10-15 20:01:20 -04:00
|
|
|
const Notifications = AstalNotifd.get_default();
|
|
|
|
|
2024-10-30 18:53:15 -04:00
|
|
|
import NotifGestureWrapper from './gesture';
|
2024-10-15 20:01:20 -04:00
|
|
|
import { Notification } from './notification';
|
|
|
|
|
|
|
|
|
|
|
|
export default () => (
|
|
|
|
<box
|
|
|
|
// Needed so it occupies space at the start
|
2024-10-16 13:16:41 -04:00
|
|
|
// It needs to be bigger than the notifs to not jiggle
|
|
|
|
css="min-width: 550px;"
|
2024-10-15 20:01:20 -04:00
|
|
|
vertical
|
|
|
|
|
|
|
|
setup={(self) => {
|
2024-10-17 11:04:24 -04:00
|
|
|
const notifQueue: number[] = [];
|
|
|
|
|
2024-10-15 20:01:20 -04:00
|
|
|
const addPopup = (id: number) => {
|
2024-10-29 17:30:40 -04:00
|
|
|
if (!id || !Notifications.get_notification(id)) {
|
2024-10-15 20:01:20 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-10-17 11:04:24 -04:00
|
|
|
if (NotifGestureWrapper.sliding_in === 0) {
|
|
|
|
const NewNotif = Notification({ id, popup_timer: 5 });
|
|
|
|
|
|
|
|
if (NewNotif) {
|
|
|
|
// Use this instead of add to put it at the top
|
|
|
|
self.pack_end(NewNotif, false, false, 0);
|
|
|
|
self.show_all();
|
|
|
|
|
|
|
|
NotifGestureWrapper.popups.set(id, NewNotif);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notifQueue.push(id);
|
|
|
|
}
|
|
|
|
};
|
2024-10-15 20:01:20 -04:00
|
|
|
|
2024-10-17 11:04:24 -04:00
|
|
|
NotifGestureWrapper.on_sliding_in = (n) => {
|
|
|
|
if (n === 0) {
|
|
|
|
const id = notifQueue.shift();
|
2024-10-15 20:01:20 -04:00
|
|
|
|
2024-10-17 11:04:24 -04:00
|
|
|
if (id) {
|
|
|
|
addPopup(id);
|
|
|
|
}
|
2024-10-15 20:01:20 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleResolved = (id: number) => {
|
2024-10-15 23:56:11 -04:00
|
|
|
const notif = NotifGestureWrapper.popups.get(id);
|
2024-10-15 20:01:20 -04:00
|
|
|
|
|
|
|
if (!notif) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
notif.slideAway('Left');
|
2024-10-15 23:56:11 -04:00
|
|
|
NotifGestureWrapper.popups.delete(id);
|
2024-10-15 20:01:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
self
|
|
|
|
.hook(Notifications, 'notified', (_, id) => addPopup(id))
|
|
|
|
.hook(Notifications, 'resolved', (_, id) => handleResolved(id));
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|