2023-10-31 08:32:40 -04:00
|
|
|
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-06 20:10:12 -05:00
|
|
|
import { Box } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-11-03 15:28:08 -04:00
|
|
|
import { interval } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
|
2024-01-13 23:38:31 -05:00
|
|
|
import { Notification } from './base.ts';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
const DELAY = 2000;
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
// Types
|
2024-01-29 20:56:56 -05:00
|
|
|
import { NotifGesture } from 'global-types';
|
2024-01-13 11:15:08 -05:00
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
export default () => Box({
|
|
|
|
vertical: true,
|
2023-12-28 23:20:03 -05:00
|
|
|
// Needed so it occupies space at the start
|
|
|
|
css: 'padding: 1px;',
|
2023-11-06 20:10:12 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
setup: (self) => {
|
2024-01-13 11:15:08 -05:00
|
|
|
const addPopup = (id: number) => {
|
2023-12-17 00:01:58 -05:00
|
|
|
if (!id) {
|
|
|
|
return;
|
2023-11-03 00:03:14 -04:00
|
|
|
}
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
const notif = Notifications.getNotification(id);
|
|
|
|
|
2023-12-20 17:14:07 -05:00
|
|
|
if (notif) {
|
|
|
|
const NewNotif = Notification({
|
|
|
|
notif,
|
2023-12-22 16:58:12 -05:00
|
|
|
command: () => {
|
|
|
|
if (notif.popup) {
|
|
|
|
notif.dismiss();
|
|
|
|
}
|
|
|
|
},
|
2023-12-20 17:14:07 -05:00
|
|
|
});
|
2023-12-17 00:01:58 -05:00
|
|
|
|
2023-12-20 17:14:07 -05:00
|
|
|
if (NewNotif) {
|
|
|
|
// Use this instead of add to put it at the top
|
|
|
|
self.pack_end(NewNotif, false, false, 0);
|
|
|
|
self.show_all();
|
|
|
|
}
|
2023-12-17 00:01:58 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
const handleDismiss = (id: number, force = false) => {
|
2024-01-29 20:56:56 -05:00
|
|
|
const notif = (self.children as NotifGesture[])
|
2024-01-13 11:15:08 -05:00
|
|
|
.find((ch) => ch.attribute.id === id);
|
2023-12-17 00:01:58 -05:00
|
|
|
|
|
|
|
if (!notif) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-18 11:01:09 -05:00
|
|
|
console.log(notif.attribute.hovered);
|
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
// If notif isn't hovered or was closed, slide away
|
2023-12-20 17:14:07 -05:00
|
|
|
if (!notif.attribute.hovered || force) {
|
|
|
|
notif.attribute.slideAway('Left');
|
2023-12-17 00:01:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// If notif is hovered, delay close
|
2023-12-20 17:14:07 -05:00
|
|
|
else if (notif.attribute.hovered) {
|
|
|
|
const intervalId = interval(DELAY, () => {
|
|
|
|
if (!notif.attribute.hovered && intervalId) {
|
|
|
|
notif.attribute.slideAway('Left');
|
|
|
|
|
|
|
|
GLib.source_remove(intervalId);
|
2023-12-17 00:01:58 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2023-11-27 15:01:54 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
self
|
|
|
|
.hook(Notifications, (_, id) => addPopup(id), 'notified')
|
|
|
|
.hook(Notifications, (_, id) => handleDismiss(id), 'dismissed')
|
|
|
|
.hook(Notifications, (_, id) => handleDismiss(id, true), 'closed');
|
|
|
|
},
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|