in kotlin-desktop-toolkit/src/main/kotlin/org/jetbrains/desktop/macos/NotificationCenter.kt [284:319]
public fun showNotification(
title: String,
body: String,
sound: NotificationSound = NotificationSound.Default,
notificationId: NotificationId,
categoryId: CategoryId = DefaultCategory,
onComplete: (error: String?) -> Unit,
) {
showNotificationCallbacks[notificationId] = onComplete
try {
ffiDownCall {
Arena.ofConfined().use { arena ->
val identifierPtr = arena.allocateUtf8String(notificationId.value)
val titlePtr = arena.allocateUtf8String(title)
val bodyPtr = arena.allocateUtf8String(body)
val soundNamePtr = arena.allocateUtf8String(sound.getSoundName())
val categoryIdPtr = arena.allocateUtf8String(categoryId.value)
// Allocate and populate the NotificationRequest struct
val requestSegment = arena.allocate(NativeNotificationRequest.layout())
NativeNotificationRequest.identifier(requestSegment, identifierPtr)
NativeNotificationRequest.title(requestSegment, titlePtr)
NativeNotificationRequest.body(requestSegment, bodyPtr)
NativeNotificationRequest.sound_type(requestSegment, sound.toNativeType())
NativeNotificationRequest.sound_name(requestSegment, soundNamePtr)
NativeNotificationRequest.category_identifier(requestSegment, categoryIdPtr)
desktop_macos_h.notification_show(requestSegment)
}
}
} catch (e: Throwable) {
showNotificationCallbacks.remove(notificationId)
throw e
}
}