2024-01-30 11:29:07 -05:00
|
|
|
const Notifications = await Service.import('notifications');
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-01-30 11:29:07 -05:00
|
|
|
const { Label, Box, Icon, Scrollable, Revealer } = Widget;
|
|
|
|
const { timeout } = Utils;
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2024-01-13 23:38:31 -05:00
|
|
|
import { Notification, HasNotifs } from './base.ts';
|
|
|
|
import CursorBox from '../misc/cursorbox.ts';
|
2023-09-11 19:57:21 -04:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
// Types
|
|
|
|
import { Notification as NotifObj } from 'resource:///com/github/Aylur/ags/service/notifications.js';
|
2024-01-29 20:56:56 -05:00
|
|
|
import { BoxGeneric, NotifGesture } from 'global-types';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-12-20 17:14:07 -05:00
|
|
|
|
2024-01-29 18:54:07 -05:00
|
|
|
const addNotif = (box: BoxGeneric, notif: NotifObj) => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (notif) {
|
|
|
|
const NewNotif = Notification({
|
|
|
|
notif,
|
|
|
|
slideIn: 'Right',
|
|
|
|
command: () => notif.close(),
|
|
|
|
});
|
2023-11-06 20:10:12 -05:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
if (NewNotif) {
|
|
|
|
box.pack_end(NewNotif, false, false, 0);
|
|
|
|
box.show_all();
|
|
|
|
}
|
2023-11-06 20:10:12 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const NotificationList = () => Box({
|
|
|
|
vertical: true,
|
|
|
|
vexpand: true,
|
|
|
|
vpack: 'start',
|
2023-12-20 17:14:07 -05:00
|
|
|
visible: HasNotifs.bind(),
|
2023-11-06 20:10:12 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
setup: (self) => {
|
2024-02-18 13:10:25 -05:00
|
|
|
const initNotifId = 1337;
|
2024-04-02 09:14:42 -04:00
|
|
|
const delay = 2000;
|
2024-02-18 13:10:25 -05:00
|
|
|
|
|
|
|
// Fix the no notif placement with a fake notif
|
|
|
|
Notifications.Notify('', initNotifId, '', '', '', [''], {}, 0);
|
|
|
|
setTimeout(() => {
|
|
|
|
Notifications.getNotification(initNotifId)?.close();
|
|
|
|
}, delay);
|
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
self
|
|
|
|
.hook(Notifications, (box, id) => {
|
|
|
|
// Handle cached notifs
|
|
|
|
if (box.children.length === 0) {
|
|
|
|
Notifications.notifications.forEach((n) => {
|
|
|
|
addNotif(box, n);
|
|
|
|
});
|
|
|
|
}
|
2023-11-06 20:10:12 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
else if (id) {
|
2023-12-20 17:14:07 -05:00
|
|
|
const notifObj = Notifications.getNotification(id);
|
|
|
|
|
|
|
|
if (notifObj) {
|
|
|
|
addNotif(box, notifObj);
|
|
|
|
}
|
2023-12-17 00:01:58 -05:00
|
|
|
}
|
|
|
|
}, 'notified')
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
.hook(Notifications, (box, id) => {
|
2024-01-29 20:56:56 -05:00
|
|
|
const notif = (box.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?.sensitive) {
|
2023-12-20 17:14:07 -05:00
|
|
|
notif.attribute.slideAway('Right');
|
2023-12-17 00:01:58 -05:00
|
|
|
}
|
|
|
|
}, 'closed');
|
|
|
|
},
|
2023-11-06 20:10:12 -05:00
|
|
|
});
|
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
const ClearButton = () => CursorBox({
|
2023-12-27 23:13:49 -05:00
|
|
|
class_name: 'clear',
|
|
|
|
|
|
|
|
on_primary_click_release: () => {
|
|
|
|
Notifications.clear();
|
|
|
|
timeout(1000, () => App.closeWindow('notification-center'));
|
|
|
|
},
|
|
|
|
|
|
|
|
setup: (self) => {
|
|
|
|
self.hook(HasNotifs, () => {
|
2024-01-29 18:54:07 -05:00
|
|
|
self.disabled = !HasNotifs.value;
|
2023-12-27 23:13:49 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
child: Box({
|
|
|
|
|
|
|
|
children: [
|
|
|
|
Label('Clear '),
|
|
|
|
|
|
|
|
Icon({
|
|
|
|
setup: (self) => {
|
|
|
|
self.hook(Notifications, () => {
|
|
|
|
self.icon = Notifications.notifications.length > 0 ?
|
|
|
|
'user-trash-full-symbolic' :
|
|
|
|
'user-trash-symbolic';
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
2023-09-15 13:51:03 -04:00
|
|
|
}),
|
|
|
|
});
|
2023-09-11 13:59:51 -04:00
|
|
|
|
|
|
|
const Header = () => Box({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'header',
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
|
|
|
Label({
|
|
|
|
label: 'Notifications',
|
|
|
|
hexpand: true,
|
|
|
|
xalign: 0,
|
|
|
|
}),
|
|
|
|
ClearButton(),
|
|
|
|
],
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
const Placeholder = () => Revealer({
|
|
|
|
transition: 'crossfade',
|
2023-12-20 17:14:07 -05:00
|
|
|
reveal_child: HasNotifs.bind()
|
|
|
|
.transform((v) => !v),
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'placeholder',
|
2023-10-20 23:11:21 -04:00
|
|
|
vertical: true,
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'center',
|
|
|
|
hpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
vexpand: true,
|
|
|
|
hexpand: true,
|
2023-12-20 17:14:07 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
|
|
|
Icon('notification-disabled-symbolic'),
|
|
|
|
Label('Your inbox is empty'),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-11-27 15:01:54 -05:00
|
|
|
export default () => Box({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'notification-center',
|
2023-10-20 23:11:21 -04:00
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
Header(),
|
2023-12-20 17:14:07 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
Box({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'notification-wallpaper-box',
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
children: [
|
2023-10-20 23:11:21 -04:00
|
|
|
Scrollable({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'notification-list-box',
|
2023-10-20 23:11:21 -04:00
|
|
|
hscroll: 'never',
|
2023-12-12 23:15:13 -05:00
|
|
|
vscroll: 'automatic',
|
2023-12-20 17:14:07 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'notification-list',
|
2023-10-20 23:11:21 -04:00
|
|
|
vertical: true,
|
2023-12-20 17:14:07 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
2023-11-03 15:28:08 -04:00
|
|
|
NotificationList(),
|
2023-12-20 17:14:07 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
Placeholder(),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}),
|
2023-10-17 13:47:02 -04:00
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
],
|
2023-09-21 20:01:14 -04:00
|
|
|
});
|