Scoop API

scoop:scoop.desktop:0.1.0

src/notification/content.scoop

Selected production source · src/notification/content.scoop

1package scoop.desktop.notification
3import scoop.desktop.desktopCreated
4import scoop.desktop.desktopStatus
6internal fun <T> withNotificationContent(
7 id: NotificationId,
8 content: NotificationContent,
9 block: (Ptr<Unit>) -> T
10): T {
11 @Unsafe
12 {
13 val native =
14 desktopCreated(
15 notificationContentCreate(
16 if (content.sound == NotificationSound.Silent)
17 1
18 else
19 0
20 ),
21 "notification content"
22 )
23 try {
24 val fields = [id.value, content.title, content.body, content.payload]
25 for (index in 0L ..< fields.size)
26 fields[index].withUtf8Bytes {
27 text,
28 length -> @Unsafe
29 {
30 desktopStatus(
31 notificationContentText(native, index.toInt(), text, length),
32 "notification text"
33 )
34 }
35 }
36 for (action in content.actions)
37 action.id.value.withUtf8Bytes {
38 id,
39 idLength -> @Unsafe
40 {
41 action.title.withUtf8Bytes {
42 title,
43 titleLength -> @Unsafe
44 {
45 desktopStatus(
46 notificationContentAction(
47 native,
48 id,
49 idLength,
50 title,
51 titleLength
52 ),
53 "notification action"
54 )
55 }
56 }
57 }
58 }
59 return block(native)
60 } finally {
61 notificationContentDestroy(native)
62 }
63 }