2023-09-11 13:59:51 -04:00
|
|
|
const { Notifications } = ags.Service;
|
2023-09-14 01:15:33 -04:00
|
|
|
const { Button, Label, Box, Icon, Scrollable, Window, Revealer } = ags.Widget;
|
2023-09-15 12:32:30 -04:00
|
|
|
const { timeout } = ags.Utils;
|
2023-09-15 13:51:03 -04:00
|
|
|
const { getWindow } = ags.App;
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-09-11 19:57:21 -04:00
|
|
|
import Notification from './base.js';
|
2023-09-21 20:01:14 -04:00
|
|
|
import { EventBox } from '../misc/cursorbox.js';
|
|
|
|
import { PopUp } from '../misc/popup.js';
|
2023-09-11 19:57:21 -04:00
|
|
|
|
2023-09-15 13:51:03 -04:00
|
|
|
const ClearButton = () => EventBox({
|
|
|
|
child: Button({
|
|
|
|
onPrimaryClickRelease: button => {
|
2023-09-21 00:27:58 -04:00
|
|
|
button._popups.children.forEach(ch => ch.child.setStyle(ch.child._leftAnim1));
|
2023-09-15 13:51:03 -04:00
|
|
|
button._notifList.children.forEach(ch => {
|
2023-09-21 00:27:58 -04:00
|
|
|
ch.child.setStyle(ch.child._rightAnim1);
|
2023-09-15 13:51:03 -04:00
|
|
|
timeout(500, () => {
|
|
|
|
button._notifList.remove(ch);
|
|
|
|
Notifications.close(ch._id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
properties: [['notifList'], ['popups']],
|
|
|
|
connections: [[Notifications, button => {
|
|
|
|
if (!button._notifList)
|
2023-09-21 20:01:14 -04:00
|
|
|
button._notifList = NotificationList;
|
2023-09-15 13:51:03 -04:00
|
|
|
|
|
|
|
if (!button._popups)
|
|
|
|
button._popups = getWindow('notifications').child.children[0].child;
|
|
|
|
|
|
|
|
button.sensitive = Notifications.notifications.length > 0;
|
|
|
|
}]],
|
|
|
|
child: Box({
|
|
|
|
children: [
|
|
|
|
Label('Clear '),
|
|
|
|
Icon({
|
|
|
|
connections: [[Notifications, icon => {
|
|
|
|
icon.icon = Notifications.notifications.length > 0
|
2023-09-11 14:18:22 -04:00
|
|
|
? 'user-trash-full-symbolic' : 'user-trash-symbolic';
|
2023-09-15 13:51:03 -04:00
|
|
|
}]],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-11 14:18:22 -04:00
|
|
|
}),
|
2023-09-15 13:51:03 -04:00
|
|
|
});
|
2023-09-11 13:59:51 -04:00
|
|
|
|
|
|
|
const Header = () => Box({
|
2023-09-11 14:18:22 -04:00
|
|
|
className: 'header',
|
|
|
|
children: [
|
|
|
|
Label({ label: 'Notifications', hexpand: true, xalign: 0 }),
|
|
|
|
ClearButton(),
|
|
|
|
],
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-09-21 20:01:14 -04:00
|
|
|
const NotificationList = Box({
|
2023-09-11 14:18:22 -04:00
|
|
|
vertical: true,
|
|
|
|
vexpand: true,
|
2023-09-15 12:32:30 -04:00
|
|
|
connections: [
|
|
|
|
[Notifications, (box, id) => {
|
|
|
|
if (box.children.length == 0) {
|
|
|
|
box.children = Notifications.notifications
|
|
|
|
.reverse()
|
|
|
|
.map(n => Notification({ ...n, command: i => Notifications.close(i), }));
|
|
|
|
}
|
|
|
|
else if (id) {
|
2023-09-19 10:22:08 -04:00
|
|
|
const NewNotif = Notification({
|
2023-09-15 12:32:30 -04:00
|
|
|
...Notifications.getNotification(id),
|
|
|
|
command: i => Notifications.close(i),
|
2023-09-19 10:22:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
if (NewNotif) {
|
|
|
|
box.add(NewNotif);
|
|
|
|
box.show_all();
|
|
|
|
}
|
2023-09-15 12:32:30 -04:00
|
|
|
}
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-09-15 12:32:30 -04:00
|
|
|
}, 'notified'],
|
|
|
|
|
|
|
|
[Notifications, (box, id) => {
|
|
|
|
for (const ch of box.children) {
|
|
|
|
if (ch._id == id) {
|
2023-09-21 00:27:58 -04:00
|
|
|
ch.child.setStyle(ch.child._rightAnim1);
|
2023-09-15 12:32:30 -04:00
|
|
|
timeout(500, () => box.remove(ch));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'closed'],
|
2023-09-15 13:51:03 -04:00
|
|
|
|
|
|
|
[Notifications, box => box.visible = Notifications.notifications.length > 0],
|
2023-09-15 12:32:30 -04:00
|
|
|
],
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-09-14 01:15:33 -04:00
|
|
|
const Placeholder = () => Revealer({
|
|
|
|
transition: 'crossfade',
|
2023-09-11 14:18:22 -04:00
|
|
|
connections: [[Notifications, box => {
|
2023-09-14 01:15:33 -04:00
|
|
|
box.revealChild = Notifications.notifications.length === 0;
|
2023-09-11 14:18:22 -04:00
|
|
|
}]],
|
2023-09-14 01:15:33 -04:00
|
|
|
child: Box({
|
|
|
|
className: 'placeholder',
|
|
|
|
vertical: true,
|
|
|
|
valign: 'center',
|
|
|
|
halign: 'center',
|
|
|
|
vexpand: true,
|
|
|
|
hexpand: true,
|
|
|
|
children: [
|
|
|
|
Icon('notification-disabled-symbolic'),
|
|
|
|
Label('Your inbox is empty'),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-09-21 20:01:14 -04:00
|
|
|
const NotificationCenterWidget = Box({
|
|
|
|
className: 'notification-center',
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
Header(),
|
|
|
|
Box({
|
|
|
|
className: 'notification-wallpaper-box',
|
|
|
|
children: [Scrollable({
|
|
|
|
className: 'notification-list-box',
|
|
|
|
hscroll: 'never',
|
|
|
|
vscroll: 'automatic',
|
|
|
|
child: Box({
|
|
|
|
className: 'notification-list',
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
NotificationList,
|
|
|
|
Placeholder(),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
})],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
export const NotificationCenter = Window({
|
|
|
|
name: 'notification-center',
|
|
|
|
layer: 'overlay',
|
|
|
|
anchor: 'top right',
|
2023-09-12 23:53:48 -04:00
|
|
|
margin: [ 8, 60, 0, 0 ],
|
2023-09-21 20:01:14 -04:00
|
|
|
child: PopUp({
|
|
|
|
name: 'notification-center',
|
|
|
|
child: NotificationCenterWidget,
|
2023-09-11 13:59:51 -04:00
|
|
|
}),
|
|
|
|
});
|