scoop:scoop.desktop:0.1.0
src/notification/content.scoop
Selected production source · src/notification/content.scoop
1
package scoop.desktop.notification3
import scoop.desktop.desktopCreated4
import scoop.desktop.desktopStatus6
internal fun <T> withNotificationContent(7
id: NotificationId,8
content: NotificationContent,9
block: (Ptr<Unit>) -> T10
): T {11
@Unsafe12
{13
val native =14
desktopCreated(15
notificationContentCreate(16
if (content.sound == NotificationSound.Silent)17
118
else19
020
),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 -> @Unsafe29
{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 -> @Unsafe40
{41
action.title.withUtf8Bytes {42
title,43
titleLength -> @Unsafe44
{45
desktopStatus(46
notificationContentAction(47
native,48
id,49
idLength,50
title,51
titleLength52
),53
"notification action"54
)55
}56
}57
}58
}59
return block(native)60
} finally {61
notificationContentDestroy(native)62
}63
}64
}