Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/notification-cancel-all-android.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"notification": patch
"notification-js": patch
---

Fix `cancel` command crashing on Android with `UninitializedPropertyAccessException` when invoked with no `notifications` argument — i.e. when the JS `cancelAll()` API or the Rust `NotificationExt::cancel_all()` SDK method is used. `CancelArgs.notifications` is now an optional list defaulting to `[]`; the handler routes an empty list to a new `TauriNotificationManager.cancelAll()` that enumerates saved notification IDs from storage and cancels each.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BatchArgs {

@InvokeArg
class CancelArgs {
lateinit var notifications: List<Int>
var notifications: List<Int> = listOf()
}

@InvokeArg
Expand Down Expand Up @@ -152,7 +152,11 @@ class NotificationPlugin(private val activity: Activity): Plugin(activity) {
@Command
fun cancel(invoke: Invoke) {
val args = invoke.parseArgs(CancelArgs::class.java)
manager.cancel(args.notifications)
if (args.notifications.isEmpty()) {
manager.cancelAll()
} else {
manager.cancel(args.notifications)
}
invoke.resolve()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ class TauriNotificationManager(
}
}

fun cancelAll() {
cancel(storage.getSavedNotificationIds().mapNotNull { it.toIntOrNull() })
}

private fun cancelTimerForNotification(notificationId: Int) {
val intent = Intent(context, TimedNotificationPublisher::class.java)
var flags = 0
Expand Down