2023-10-31 08:32:40 -04:00
|
|
|
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
|
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';
|
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
import { Notification } from './base.js';
|
2023-11-06 20:10:12 -05:00
|
|
|
import PopupWindow from '../misc/popup.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-11-06 20:10:12 -05:00
|
|
|
const addPopup = (box, id) => {
|
|
|
|
if (!id)
|
|
|
|
return;
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-06 20:10:12 -05:00
|
|
|
const notif = Notifications.getNotification(id);
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-06 20:10:12 -05:00
|
|
|
const NewNotif = Notification({
|
|
|
|
notif,
|
|
|
|
command: () => notif.dismiss(),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (NewNotif) {
|
|
|
|
// use this instead of add to put it at the top
|
|
|
|
box.pack_end(NewNotif, false, false, 0);
|
|
|
|
box.show_all();
|
|
|
|
}
|
|
|
|
};
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-06 20:10:12 -05:00
|
|
|
const handleDismiss = (box, id, force = false) => {
|
|
|
|
const notif = box.children.find(ch => ch._id === id);
|
|
|
|
if (!notif)
|
|
|
|
return;
|
2023-11-03 15:28:08 -04:00
|
|
|
|
2023-11-06 20:10:12 -05:00
|
|
|
// If notif isn't hovered or was closed, slide away
|
|
|
|
if (!notif._hovered || force) {
|
|
|
|
notif.slideAway('Left');
|
|
|
|
return;
|
|
|
|
}
|
2023-11-03 15:28:08 -04:00
|
|
|
|
2023-11-06 20:10:12 -05:00
|
|
|
// If notif is hovered, delay close
|
|
|
|
else if (notif._hovered) {
|
|
|
|
notif.interval = interval(2000, () => {
|
|
|
|
if (!notif._hovered && notif.interval) {
|
|
|
|
notif.slideAway('Left');
|
|
|
|
|
|
|
|
GLib.source_remove(notif.interval);
|
|
|
|
notif.interval = undefined;
|
|
|
|
return;
|
2023-11-03 00:03:14 -04:00
|
|
|
}
|
2023-11-06 20:10:12 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-11-06 20:10:12 -05:00
|
|
|
export default () => PopupWindow({
|
2023-10-20 23:11:21 -04:00
|
|
|
name: 'notifications',
|
|
|
|
anchor: ['top', 'left'],
|
2023-11-06 20:10:12 -05:00
|
|
|
visible: true,
|
|
|
|
transition: 'none',
|
2023-11-06 21:36:12 -05:00
|
|
|
closeOnUnfocus: 'stay',
|
2023-11-03 15:28:08 -04:00
|
|
|
child: Box({
|
2023-11-06 20:10:12 -05:00
|
|
|
vertical: true,
|
|
|
|
connections: [
|
|
|
|
[Notifications, (box, id) => addPopup(box, id), 'notified'],
|
|
|
|
[Notifications, (box, id) => handleDismiss(box, id), 'dismissed'],
|
|
|
|
[Notifications, (box, id) => handleDismiss(box, id, true), 'closed'],
|
|
|
|
],
|
2023-11-03 15:28:08 -04:00
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|