1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
import { type Notification as Notif } from "types/service/notifications"
import Notification from "widget/notifications/Notification"
import options from "options"
import icons from "lib/icons"
const notifications = await Service.import("notifications")
const notifs = notifications.bind("notifications")
const Animated = (n: Notif) => Widget.Revealer({
transition_duration: options.transition.value,
transition: "slide_down",
child: Notification(n),
setup: self => Utils.timeout(options.transition.value, () => {
if (!self.is_destroyed)
self.reveal_child = true
}),
})
const ClearButton = () => Widget.Button({
on_clicked: notifications.clear,
sensitive: notifs.as(n => n.length > 0),
child: Widget.Box({
children: [
Widget.Label("Clear "),
Widget.Icon({
icon: notifs.as(n => icons.trash[n.length > 0 ? "full" : "empty"]),
}),
],
}),
})
const Header = () => Widget.Box({
class_name: "header",
children: [
Widget.Label({ label: "Notifications", hexpand: true, xalign: 0 }),
ClearButton(),
],
})
const NotificationList = () => {
const map: Map<number, ReturnType<typeof Animated>> = new Map
const box = Widget.Box({
vertical: true,
children: notifications.notifications.map(n => {
const w = Animated(n)
map.set(n.id, w)
return w
}),
visible: notifs.as(n => n.length > 0),
})
function remove(_: unknown, id: number) {
const n = map.get(id)
if (n) {
n.reveal_child = false
Utils.timeout(options.transition.value, () => {
n.destroy()
map.delete(id)
})
}
}
return box
.hook(notifications, remove, "closed")
.hook(notifications, (_, id: number) => {
if (id !== undefined) {
if (map.has(id))
remove(null, id)
const n = notifications.getNotification(id)!
const w = Animated(n)
map.set(id, w)
box.children = [w, ...box.children]
}
}, "notified")
}
const Placeholder = () => Widget.Box({
class_name: "placeholder",
vertical: true,
vpack: "center",
hpack: "center",
vexpand: true,
hexpand: true,
visible: notifs.as(n => n.length === 0),
children: [
Widget.Icon(icons.notifications.silent),
Widget.Label("Your inbox is empty"),
],
})
export default () => Widget.Box({
class_name: "notifications",
css: options.notifications.width.bind().as(w => `min-width: ${w}px`),
vertical: true,
children: [
Header(),
Widget.Scrollable({
vexpand: true,
hscroll: "never",
class_name: "notification-scrollable",
child: Widget.Box({
class_name: "notification-list vertical",
vertical: true,
children: [
NotificationList(),
Placeholder(),
],
}),
}),
],
})
|