From d2539e2d201e9ae31de00c4f666c1725e214aa05 Mon Sep 17 00:00:00 2001 From: Jenna Antilla <46546946+jennantilla@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:30:57 -0700 Subject: [PATCH 1/2] Move notification click listener from initialization to native method - Ensures that the notification click listener fires on app cold start --- src/android/com/onesignal/cordova/OneSignalPush.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/com/onesignal/cordova/OneSignalPush.java b/src/android/com/onesignal/cordova/OneSignalPush.java index 9ff4236d..54f4b3a0 100644 --- a/src/android/com/onesignal/cordova/OneSignalPush.java +++ b/src/android/com/onesignal/cordova/OneSignalPush.java @@ -237,6 +237,7 @@ private boolean preventDefault(JSONArray data) { */ public boolean addNotificationClickListener(CallbackContext callbackContext) { + OneSignal.getNotifications().addClickListener(this); jsNotificationClickedCallback = callbackContext; return true; } @@ -361,7 +362,6 @@ public boolean init(CallbackContext callbackContext, JSONArray data) { OneSignal.getInAppMessages().addLifecycleListener(this); OneSignal.getInAppMessages().addClickListener(this); OneSignal.getNotifications().addForegroundLifecycleListener(this); - OneSignal.getNotifications().addClickListener(this); CallbackHelper.callbackSuccessBoolean(callbackContext, true); return true; From dd3f899f6f1c36573f5d92a1c06b6f8a1c59f0f7 Mon Sep 17 00:00:00 2001 From: Jenna Antilla <46546946+jennantilla@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:52:00 -0700 Subject: [PATCH 2/2] Add conditional check to only add notification click listener once - Introduced a boolean flag to track whether the notification click listener has already been added - Updated `addNotificationClickListener` method to only add the listener if it hasn't been added yet --- .../com/onesignal/cordova/OneSignalPush.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/android/com/onesignal/cordova/OneSignalPush.java b/src/android/com/onesignal/cordova/OneSignalPush.java index 54f4b3a0..8817f506 100644 --- a/src/android/com/onesignal/cordova/OneSignalPush.java +++ b/src/android/com/onesignal/cordova/OneSignalPush.java @@ -236,10 +236,17 @@ private boolean preventDefault(JSONArray data) { * N O T I F I C A T I O N C L I C K L I S T E N E R */ + private boolean hasAddedNotificationClickListener = false; + public boolean addNotificationClickListener(CallbackContext callbackContext) { - OneSignal.getNotifications().addClickListener(this); - jsNotificationClickedCallback = callbackContext; - return true; + if (this.hasAddedNotificationClickListener) { + return false; + } + + OneSignal.getNotifications().addClickListener(this); + jsNotificationClickedCallback = callbackContext; + hasAddedNotificationClickListener = true; + return true; } @Override