public fun registerNotificationCategories()

in kotlin-desktop-toolkit/src/main/kotlin/org/jetbrains/desktop/macos/NotificationCenter.kt [205:262]


    public fun registerNotificationCategories(categories: List<NotificationCategory>) {
        ffiDownCall {
            Arena.ofConfined().use { arena ->
                // Allocate array of NativeNotificationCategory structs
                val categoriesArray = arena.allocateArray(NativeNotificationCategory.layout(), categories.size.toLong())

                categories.forEachIndexed { categoryIndex, category ->
                    val categorySegment = categoriesArray.asSlice(
                        categoryIndex * NativeNotificationCategory.layout().byteSize(),
                        NativeNotificationCategory.layout(),
                    )

                    // Allocate category ID
                    val categoryIdPtr = arena.allocateUtf8String(category.categoryId.value)
                    NativeNotificationCategory.category_id(categorySegment, categoryIdPtr)

                    // Allocate array of NativeNotificationAction structs for this category
                    val actionsArray = arena.allocateArray(NativeNotificationAction.layout(), category.actions.size.toLong())
                    category.actions.forEachIndexed { actionIndex, action ->
                        val actionSegment = actionsArray.asSlice(
                            actionIndex * NativeNotificationAction.layout().byteSize(),
                            NativeNotificationAction.layout(),
                        )

                        val actionIdPtr = arena.allocateUtf8String(action.actionId.value)
                        val actionTitlePtr = arena.allocateUtf8String(action.title)

                        NativeNotificationAction.identifier(actionSegment, actionIdPtr)
                        NativeNotificationAction.title(actionSegment, actionTitlePtr)

                        // Set action options
                        val optionsSegment = NativeNotificationAction.options(actionSegment)
                        NativeNotificationActionOptionsFlags.foreground(optionsSegment, action.isForeground)
                        NativeNotificationActionOptionsFlags.destructive(optionsSegment, action.isDestructive)
                        NativeNotificationActionOptionsFlags.authentication_required(optionsSegment, action.requiresAuthentication)
                    }

                    // Create BorrowedArray for actions
                    val borrowedActionsArray = arena.allocate(NativeBorrowedArray_NotificationAction.layout())
                    NativeBorrowedArray_NotificationAction.ptr(borrowedActionsArray, actionsArray)
                    NativeBorrowedArray_NotificationAction.len(borrowedActionsArray, category.actions.size.toLong())
                    NativeBorrowedArray_NotificationAction.deinit(borrowedActionsArray, MemorySegment.NULL)

                    // Set the actions array on the category
                    NativeNotificationCategory.actions(categorySegment, borrowedActionsArray)
                }

                // Create BorrowedArray for categories
                val borrowedCategoriesArray = arena.allocate(NativeBorrowedArray_NotificationCategory.layout())
                NativeBorrowedArray_NotificationCategory.ptr(borrowedCategoriesArray, categoriesArray)
                NativeBorrowedArray_NotificationCategory.len(borrowedCategoriesArray, categories.size.toLong())
                NativeBorrowedArray_NotificationCategory.deinit(borrowedCategoriesArray, MemorySegment.NULL)

                // Register the categories
                desktop_macos_h.register_notification_categories(borrowedCategoriesArray)
            }
        }
    }