react-native-push-signal 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/README.ru.md +13 -2
- package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignal.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignalCenter.kt +124 -6
- package/ios/PushSignal.swift +1 -1
- package/ios/PushSignalCenter.swift +36 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/pushSignal.js.map +1 -1
- package/lib/module/pushSignal.native.js +9 -2
- package/lib/module/pushSignal.native.js.map +1 -1
- package/lib/typescript/src/PushSignal.nitro.d.ts +2 -1
- package/lib/typescript/src/PushSignal.nitro.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/pushSignal.d.ts +2 -2
- package/lib/typescript/src/pushSignal.d.ts.map +1 -1
- package/lib/typescript/src/pushSignal.native.d.ts +2 -2
- package/lib/typescript/src/pushSignal.native.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.hpp +128 -0
- package/nitrogen/generated/android/c++/JHybridPushSignalSpec.cpp +5 -4
- package/nitrogen/generated/android/c++/JHybridPushSignalSpec.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/HybridPushSignalSpec.kt +2 -2
- package/nitrogen/generated/android/pushsignalOnLoad.cpp +2 -0
- package/nitrogen/generated/ios/PushSignal-Swift-Cxx-Bridge.cpp +25 -0
- package/nitrogen/generated/ios/PushSignal-Swift-Cxx-Bridge.hpp +91 -0
- package/nitrogen/generated/ios/c++/HybridPushSignalSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.swift +61 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_bool__.swift +66 -0
- package/nitrogen/generated/ios/swift/HybridPushSignalSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridPushSignalSpec_cxx.swift +26 -5
- package/nitrogen/generated/shared/c++/HybridPushSignalSpec.hpp +1 -1
- package/package.json +1 -1
- package/src/PushSignal.nitro.ts +5 -1
- package/src/index.tsx +1 -0
- package/src/pushSignal.native.tsx +15 -6
- package/src/pushSignal.tsx +2 -3
package/README.md
CHANGED
|
@@ -44,6 +44,10 @@ const credentials = await getCredentials();
|
|
|
44
44
|
|
|
45
45
|
const stopMessages = onMessage((message) => {
|
|
46
46
|
console.log('incoming', message);
|
|
47
|
+
if (message.data.silent === '1') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
const stopPress = onNotificationPress((message) => {
|
|
@@ -112,13 +116,20 @@ If the host app already declares its own `FirebaseMessagingService`, only one se
|
|
|
112
116
|
|
|
113
117
|
## Incoming messages vs taps
|
|
114
118
|
|
|
115
|
-
|
|
119
|
+
| App state | iOS | Android (notification payload) | Android (data-only) |
|
|
120
|
+
| --- | --- | --- | --- |
|
|
121
|
+
| Foreground | `onMessage`. Banner if a listener returns `true` | `onMessage`. Banner if a listener returns `true` | `onMessage`. Tray only if a listener returns `true` and the payload has title or body |
|
|
122
|
+
| Background / killed | System banner. Tap → `onNotificationPress` | System banner. Tap → `onNotificationPress` | No banner. `onMessage` if the process is alive |
|
|
123
|
+
|
|
124
|
+
- `onMessage` — the push arrived while the app is in the foreground (and Android data messages while the process is alive). Return `true` to show the system banner as usual. No return, `false`, or a throw means no banner. If several listeners are registered, the banner shows when any of them returns `true`.
|
|
116
125
|
- `onNotificationPress` — the user opened the notification, including a cold start.
|
|
117
126
|
- On iOS, a visible push received in the background or when the app is killed is delivered on tap, not through `onMessage`. That is an OS limit.
|
|
118
127
|
|
|
128
|
+
If `onMessage` throws or takes longer than about 2 seconds, the library does not show a banner.
|
|
129
|
+
|
|
119
130
|
## Web
|
|
120
131
|
|
|
121
|
-
`initialize()` resolves. `getCredentials()` throws. Listeners are no-ops.
|
|
132
|
+
`initialize()` resolves. `getCredentials()` throws. Listeners (`onMessage`, `onNotificationPress`) are no-ops.
|
|
122
133
|
|
|
123
134
|
## Contributing
|
|
124
135
|
|
package/README.ru.md
CHANGED
|
@@ -44,6 +44,10 @@ const credentials = await getCredentials();
|
|
|
44
44
|
|
|
45
45
|
const stopMessages = onMessage((message) => {
|
|
46
46
|
console.log('incoming', message);
|
|
47
|
+
if (message.data.silent === '1') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
const stopPress = onNotificationPress((message) => {
|
|
@@ -112,13 +116,20 @@ apply plugin: "com.google.gms.google-services"
|
|
|
112
116
|
|
|
113
117
|
## Входящее сообщение и тап
|
|
114
118
|
|
|
115
|
-
|
|
119
|
+
| Состояние | iOS | Android (notification payload) | Android (data-only) |
|
|
120
|
+
| --- | --- | --- | --- |
|
|
121
|
+
| Foreground | `onMessage`. Баннер, если слушатель вернул `true` | `onMessage`. Баннер, если слушатель вернул `true` | `onMessage`. Tray только если слушатель вернул `true` и в payload есть title или body |
|
|
122
|
+
| Background / killed | Системный баннер. Тап → `onNotificationPress` | Системный баннер. Тап → `onNotificationPress` | Баннера нет. `onMessage`, если процесс жив |
|
|
123
|
+
|
|
124
|
+
- `onMessage` — пуш пришёл, пока приложение на переднем плане (и Android data-message, пока процесс жив). Верните `true`, чтобы показать системный баннер как обычно. Без return, `false` или ошибка — баннера нет. Если слушателей несколько, баннер показывается, когда любой вернул `true`.
|
|
116
125
|
- `onNotificationPress` — пользователь открыл уведомление, в том числе при холодном старте.
|
|
117
126
|
- На iOS видимый пуш в фоне или при убитом приложении приходит только в тап, не в `onMessage`. Это ограничение ОС.
|
|
118
127
|
|
|
128
|
+
Если `onMessage` бросил ошибку или не ответил примерно за 2 секунды, баннер не показывается.
|
|
129
|
+
|
|
119
130
|
## Web
|
|
120
131
|
|
|
121
|
-
`initialize()` резолвится. `getCredentials()` бросает ошибку. Слушатели ничего не делают.
|
|
132
|
+
`initialize()` резолвится. `getCredentials()` бросает ошибку. Слушатели (`onMessage`, `onNotificationPress`) ничего не делают.
|
|
122
133
|
|
|
123
134
|
## Contributing
|
|
124
135
|
|
|
@@ -28,7 +28,7 @@ class PushSignal : HybridPushSignalSpec() {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
override fun setOnMessage(callback: (message: PushMessage) ->
|
|
31
|
+
override fun setOnMessage(callback: (message: PushMessage) -> Promise<Promise<Boolean>>) {
|
|
32
32
|
PushSignalCenter.setOnMessage(callback)
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -2,26 +2,39 @@ package com.margelo.nitro.pushsignal
|
|
|
2
2
|
|
|
3
3
|
import android.app.Activity
|
|
4
4
|
import android.app.Application
|
|
5
|
+
import android.app.NotificationChannel
|
|
6
|
+
import android.app.NotificationManager
|
|
7
|
+
import android.app.PendingIntent
|
|
5
8
|
import android.content.Context
|
|
6
9
|
import android.content.Intent
|
|
10
|
+
import android.os.Build
|
|
7
11
|
import android.os.Bundle
|
|
12
|
+
import android.os.Handler
|
|
13
|
+
import android.os.Looper
|
|
8
14
|
import androidx.activity.ComponentActivity
|
|
15
|
+
import androidx.core.app.NotificationCompat
|
|
9
16
|
import com.google.firebase.FirebaseApp
|
|
10
17
|
import com.google.firebase.FirebaseOptions
|
|
11
18
|
import com.google.firebase.messaging.FirebaseMessaging
|
|
12
19
|
import com.google.android.gms.tasks.Tasks
|
|
13
20
|
import com.google.firebase.messaging.RemoteMessage
|
|
21
|
+
import com.margelo.nitro.core.Promise
|
|
14
22
|
import java.util.Collections
|
|
23
|
+
import java.util.UUID
|
|
15
24
|
import java.util.WeakHashMap
|
|
16
25
|
import java.util.concurrent.CopyOnWriteArrayList
|
|
26
|
+
import java.util.concurrent.atomic.AtomicBoolean
|
|
17
27
|
|
|
18
28
|
internal object PushSignalCenter : Application.ActivityLifecycleCallbacks {
|
|
19
29
|
private const val EXTRA_HANDLED = "pushsignal.handled"
|
|
30
|
+
private const val CHANNEL_ID = "push_signal_default"
|
|
31
|
+
private const val FOREGROUND_TIMEOUT_MS = 2_000L
|
|
20
32
|
|
|
21
33
|
private val lock = Any()
|
|
34
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
22
35
|
@Volatile private var application: Application? = null
|
|
23
36
|
@Volatile private var currentActivity: Activity? = null
|
|
24
|
-
@Volatile private var onMessage: ((PushMessage) ->
|
|
37
|
+
@Volatile private var onMessage: ((PushMessage) -> Promise<Promise<Boolean>>)? = null
|
|
25
38
|
@Volatile private var onNotificationPress: ((PushMessage) -> Unit)? = null
|
|
26
39
|
@Volatile private var pendingPress: PushMessage? = null
|
|
27
40
|
private val registeredActivities = Collections.newSetFromMap(WeakHashMap<Activity, Boolean>())
|
|
@@ -63,7 +76,7 @@ internal object PushSignalCenter : Application.ActivityLifecycleCallbacks {
|
|
|
63
76
|
onDone(applyFirebaseConfig(context, config))
|
|
64
77
|
}
|
|
65
78
|
|
|
66
|
-
fun setOnMessage(callback: (PushMessage) ->
|
|
79
|
+
fun setOnMessage(callback: (PushMessage) -> Promise<Promise<Boolean>>) {
|
|
67
80
|
onMessage = callback
|
|
68
81
|
}
|
|
69
82
|
|
|
@@ -112,12 +125,117 @@ internal object PushSignalCenter : Application.ActivityLifecycleCallbacks {
|
|
|
112
125
|
return token
|
|
113
126
|
}
|
|
114
127
|
|
|
115
|
-
fun emitMessage(
|
|
116
|
-
|
|
128
|
+
fun emitMessage(remoteMessage: RemoteMessage) {
|
|
129
|
+
val message = remoteMessage.toPushMessage()
|
|
130
|
+
val inForeground = currentActivity != null
|
|
131
|
+
resolveShouldShowBanner(message) { shouldShow ->
|
|
132
|
+
if (
|
|
133
|
+
shouldShow &&
|
|
134
|
+
inForeground &&
|
|
135
|
+
(!message.title.isNullOrEmpty() || !message.body.isNullOrEmpty())
|
|
136
|
+
) {
|
|
137
|
+
postForegroundNotification(message)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
117
140
|
}
|
|
118
141
|
|
|
119
|
-
fun
|
|
120
|
-
|
|
142
|
+
private fun resolveShouldShowBanner(
|
|
143
|
+
message: PushMessage,
|
|
144
|
+
onDone: (Boolean) -> Unit
|
|
145
|
+
) {
|
|
146
|
+
val callback = onMessage
|
|
147
|
+
if (callback == null) {
|
|
148
|
+
onDone(false)
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
val delivered = AtomicBoolean(false)
|
|
153
|
+
val timeout = Runnable {
|
|
154
|
+
if (delivered.compareAndSet(false, true)) {
|
|
155
|
+
onDone(false)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
mainHandler.postDelayed(timeout, FOREGROUND_TIMEOUT_MS)
|
|
159
|
+
|
|
160
|
+
val finish = { shouldShow: Boolean ->
|
|
161
|
+
if (delivered.compareAndSet(false, true)) {
|
|
162
|
+
mainHandler.removeCallbacks(timeout)
|
|
163
|
+
onDone(shouldShow)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
callback(message)
|
|
169
|
+
.then { inner ->
|
|
170
|
+
inner
|
|
171
|
+
.then { shouldShow -> finish(shouldShow) }
|
|
172
|
+
.catch { finish(false) }
|
|
173
|
+
}
|
|
174
|
+
.catch { finish(false) }
|
|
175
|
+
} catch (_: Throwable) {
|
|
176
|
+
finish(false)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private fun postForegroundNotification(message: PushMessage) {
|
|
181
|
+
val context = application ?: return
|
|
182
|
+
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
|
|
183
|
+
?: return
|
|
184
|
+
|
|
185
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
186
|
+
val existing = manager.getNotificationChannel(CHANNEL_ID)
|
|
187
|
+
if (existing == null) {
|
|
188
|
+
manager.createNotificationChannel(
|
|
189
|
+
NotificationChannel(
|
|
190
|
+
CHANNEL_ID,
|
|
191
|
+
"Notifications",
|
|
192
|
+
NotificationManager.IMPORTANCE_HIGH
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
|
199
|
+
?: return
|
|
200
|
+
launchIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
|
201
|
+
launchIntent.putExtra("google.message_id", message.id ?: UUID.randomUUID().toString())
|
|
202
|
+
message.title?.let { launchIntent.putExtra("gcm.notification.title", it) }
|
|
203
|
+
message.body?.let { launchIntent.putExtra("gcm.notification.body", it) }
|
|
204
|
+
message.data.forEach { (key, value) ->
|
|
205
|
+
launchIntent.putExtra(key, value)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
val requestCode = (message.id ?: message.title ?: "push").hashCode()
|
|
209
|
+
val pendingIntent = PendingIntent.getActivity(
|
|
210
|
+
context,
|
|
211
|
+
requestCode,
|
|
212
|
+
launchIntent,
|
|
213
|
+
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
val builder = NotificationCompat.Builder(context, CHANNEL_ID)
|
|
217
|
+
.setSmallIcon(smallIcon(context))
|
|
218
|
+
.setContentTitle(message.title.orEmpty())
|
|
219
|
+
.setContentText(message.body.orEmpty())
|
|
220
|
+
.setContentIntent(pendingIntent)
|
|
221
|
+
.setAutoCancel(true)
|
|
222
|
+
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
|
223
|
+
.setDefaults(NotificationCompat.DEFAULT_SOUND)
|
|
224
|
+
.setNumber(1)
|
|
225
|
+
|
|
226
|
+
manager.notify(requestCode, builder.build())
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private fun smallIcon(context: Context): Int {
|
|
230
|
+
val named = context.resources.getIdentifier("ic_notification", "drawable", context.packageName)
|
|
231
|
+
if (named != 0) {
|
|
232
|
+
return named
|
|
233
|
+
}
|
|
234
|
+
val appIcon = context.applicationInfo.icon
|
|
235
|
+
if (appIcon != 0) {
|
|
236
|
+
return appIcon
|
|
237
|
+
}
|
|
238
|
+
return android.R.drawable.stat_notify_more
|
|
121
239
|
}
|
|
122
240
|
|
|
123
241
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
package/ios/PushSignal.swift
CHANGED
|
@@ -19,7 +19,7 @@ class PushSignal: HybridPushSignalSpec {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
func setOnMessage(callback: @escaping (PushMessage) ->
|
|
22
|
+
func setOnMessage(callback: @escaping (PushMessage) -> Promise<Promise<Bool>>) throws {
|
|
23
23
|
PushSignalCenter.shared.onMessage = callback
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import NitroModules
|
|
2
3
|
import ObjectiveC
|
|
3
4
|
import UIKit
|
|
4
5
|
import UserNotifications
|
|
@@ -21,7 +22,7 @@ final class PushSignalCenter: NSObject, UNUserNotificationCenterDelegate {
|
|
|
21
22
|
private var pendingLaunchOptions: [AnyHashable: Any]?
|
|
22
23
|
private var didCaptureLaunchNotification = false
|
|
23
24
|
|
|
24
|
-
var onMessage: ((PushMessage) ->
|
|
25
|
+
var onMessage: ((PushMessage) -> Promise<Promise<Bool>>)?
|
|
25
26
|
var onNotificationPress: ((PushMessage) -> Void)? {
|
|
26
27
|
didSet {
|
|
27
28
|
flushPendingPress()
|
|
@@ -74,8 +75,11 @@ final class PushSignalCenter: NSObject, UNUserNotificationCenterDelegate {
|
|
|
74
75
|
willPresent notification: UNNotification,
|
|
75
76
|
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
|
|
76
77
|
) {
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
let message = Self.message(from: notification)
|
|
79
|
+
Task {
|
|
80
|
+
let shouldShow = await self.shouldShowForegroundBanner(for: message)
|
|
81
|
+
completionHandler(shouldShow ? Self.foregroundPresentationOptions : [])
|
|
82
|
+
}
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
func userNotificationCenter(
|
|
@@ -152,10 +156,36 @@ final class PushSignalCenter: NSObject, UNUserNotificationCenterDelegate {
|
|
|
152
156
|
waiters.forEach { $0(result) }
|
|
153
157
|
}
|
|
154
158
|
|
|
155
|
-
private func
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
private func shouldShowForegroundBanner(for message: PushMessage) async -> Bool {
|
|
160
|
+
guard let callback = onMessage else {
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return await withTaskGroup(of: Bool.self) { group in
|
|
165
|
+
group.addTask {
|
|
166
|
+
do {
|
|
167
|
+
let inner = try await callback(message).await()
|
|
168
|
+
return try await inner.await()
|
|
169
|
+
} catch {
|
|
170
|
+
return false
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
group.addTask {
|
|
174
|
+
try? await Task.sleep(nanoseconds: 2_000_000_000)
|
|
175
|
+
return false
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let first = await group.next() ?? false
|
|
179
|
+
group.cancelAll()
|
|
180
|
+
return first
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private static var foregroundPresentationOptions: UNNotificationPresentationOptions {
|
|
185
|
+
if #available(iOS 14.0, *) {
|
|
186
|
+
return [.banner, .list, .sound, .badge]
|
|
158
187
|
}
|
|
188
|
+
return [.alert, .sound, .badge]
|
|
159
189
|
}
|
|
160
190
|
|
|
161
191
|
private func emitPress(_ message: PushMessage) {
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getCredentials","initialize","onMessage","onNotificationPress"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["getCredentials","initialize","onMessage","onNotificationPress"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAQA,SACEA,cAAc,EACdC,UAAU,EACVC,SAAS,EACTC,mBAAmB,QACd,cAAc","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["initialize","_config","getCredentials","Error","onMessage","_listener","onNotificationPress"],"sourceRoot":"../../src","sources":["pushSignal.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["initialize","_config","getCredentials","Error","onMessage","_listener","onNotificationPress"],"sourceRoot":"../../src","sources":["pushSignal.tsx"],"mappings":";;AAOA,OAAO,eAAeA,UAAUA,CAC9BC,OAA8B,GAAG,CAAC,CAAC,EACpB,CAAC;AAElB,OAAO,eAAeC,cAAcA,CAAA,EAA6B;EAC/D,MAAM,IAAIC,KAAK,CAAC,2CAA2C,CAAC;AAC9D;AAEA,OAAO,SAASC,SAASA,CAACC,SAA4B,EAAc;EAClE,OAAO,MAAM,CAAC,CAAC;AACjB;AAEA,OAAO,SAASC,mBAAmBA,CACjCD,SAAyC,EAC7B;EACZ,OAAO,MAAM,CAAC,CAAC;AACjB","ignoreList":[]}
|
|
@@ -10,8 +10,15 @@ function bindNativeCallbacks() {
|
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
nativeCallbacksBound = true;
|
|
13
|
-
PushSignalHybridObject.setOnMessage(message => {
|
|
14
|
-
messageListeners.
|
|
13
|
+
PushSignalHybridObject.setOnMessage(async message => {
|
|
14
|
+
const results = await Promise.all([...messageListeners].map(async listener => {
|
|
15
|
+
try {
|
|
16
|
+
return await listener(message);
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
return results.some(result => result === true);
|
|
15
22
|
});
|
|
16
23
|
PushSignalHybridObject.setOnNotificationPress(message => {
|
|
17
24
|
pressListeners.forEach(listener => listener(message));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NitroModules","PushSignalHybridObject","createHybridObject","messageListeners","Set","pressListeners","nativeCallbacksBound","bindNativeCallbacks","setOnMessage","message","
|
|
1
|
+
{"version":3,"names":["NitroModules","PushSignalHybridObject","createHybridObject","messageListeners","Set","pressListeners","nativeCallbacksBound","bindNativeCallbacks","setOnMessage","message","results","Promise","all","map","listener","some","result","setOnNotificationPress","forEach","initialize","config","getCredentials","onMessage","add","delete","onNotificationPress"],"sourceRoot":"../../src","sources":["pushSignal.native.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AASzD,MAAMC,sBAAsB,GAC1BD,YAAY,CAACE,kBAAkB,CAAa,YAAY,CAAC;AAE3D,MAAMC,gBAAgB,GAAG,IAAIC,GAAG,CAAoB,CAAC;AACrD,MAAMC,cAAc,GAAG,IAAID,GAAG,CAAiC,CAAC;AAChE,IAAIE,oBAAoB,GAAG,KAAK;AAEhC,SAASC,mBAAmBA,CAAA,EAAG;EAC7B,IAAID,oBAAoB,EAAE;IACxB;EACF;EAEAA,oBAAoB,GAAG,IAAI;EAE3BL,sBAAsB,CAACO,YAAY,CAAC,MAAOC,OAAO,IAAK;IACrD,MAAMC,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC/B,CAAC,GAAGT,gBAAgB,CAAC,CAACU,GAAG,CAAC,MAAOC,QAAQ,IAAK;MAC5C,IAAI;QACF,OAAO,MAAMA,QAAQ,CAACL,OAAO,CAAC;MAChC,CAAC,CAAC,MAAM;QACN,OAAO,KAAK;MACd;IACF,CAAC,CACH,CAAC;IAED,OAAOC,OAAO,CAACK,IAAI,CAAEC,MAAM,IAAKA,MAAM,KAAK,IAAI,CAAC;EAClD,CAAC,CAAC;EAEFf,sBAAsB,CAACgB,sBAAsB,CAAER,OAAO,IAAK;IACzDJ,cAAc,CAACa,OAAO,CAAEJ,QAAQ,IAAKA,QAAQ,CAACL,OAAO,CAAC,CAAC;EACzD,CAAC,CAAC;AACJ;AAEA,OAAO,SAASU,UAAUA,CAACC,MAA6B,GAAG,CAAC,CAAC,EAAiB;EAC5E,OAAOnB,sBAAsB,CAACkB,UAAU,CAACC,MAAM,CAAC;AAClD;AAEA,OAAO,SAASC,cAAcA,CAAA,EAA6B;EACzD,OAAOpB,sBAAsB,CAACoB,cAAc,CAAC,CAAC;AAChD;AAEA,OAAO,SAASC,SAASA,CAACR,QAA2B,EAAc;EACjEP,mBAAmB,CAAC,CAAC;EACrBJ,gBAAgB,CAACoB,GAAG,CAACT,QAAQ,CAAC;EAC9B,OAAO,MAAM;IACXX,gBAAgB,CAACqB,MAAM,CAACV,QAAQ,CAAC;EACnC,CAAC;AACH;AAEA,OAAO,SAASW,mBAAmBA,CACjCX,QAAwC,EAC5B;EACZP,mBAAmB,CAAC,CAAC;EACrBF,cAAc,CAACkB,GAAG,CAACT,QAAQ,CAAC;EAC5B,OAAO,MAAM;IACXT,cAAc,CAACmB,MAAM,CAACV,QAAQ,CAAC;EACjC,CAAC;AACH","ignoreList":[]}
|
|
@@ -13,6 +13,7 @@ export interface PushMessage {
|
|
|
13
13
|
body?: string;
|
|
14
14
|
data: Record<string, string>;
|
|
15
15
|
}
|
|
16
|
+
export type OnMessageListener = (message: PushMessage) => boolean | void | Promise<boolean | void>;
|
|
16
17
|
export interface AndroidFirebaseConfig {
|
|
17
18
|
project_id?: string;
|
|
18
19
|
mobilesdk_app_id?: string;
|
|
@@ -25,7 +26,7 @@ export interface PushSignal extends HybridObject<{
|
|
|
25
26
|
}> {
|
|
26
27
|
initialize(config: AndroidFirebaseConfig): Promise<void>;
|
|
27
28
|
getCredentials(): Promise<PushCredentials>;
|
|
28
|
-
setOnMessage(callback: (message: PushMessage) =>
|
|
29
|
+
setOnMessage(callback: (message: PushMessage) => Promise<boolean>): void;
|
|
29
30
|
setOnNotificationPress(callback: (message: PushMessage) => void): void;
|
|
30
31
|
}
|
|
31
32
|
//# sourceMappingURL=PushSignal.nitro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PushSignal.nitro.d.ts","sourceRoot":"","sources":["../../../src/PushSignal.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,8FAA8F;AAC9F,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,YAAY,CAAC;AAChD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,YAAY,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY,CAAC;IAC/C,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;IACA,UAAU,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,cAAc,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3C,YAAY,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,
|
|
1
|
+
{"version":3,"file":"PushSignal.nitro.d.ts","sourceRoot":"","sources":["../../../src/PushSignal.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,8FAA8F;AAC9F,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,YAAY,CAAC;AAChD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,YAAY,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,WAAW,KACjB,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;AAE9C,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY,CAAC;IAC/C,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;IACA,UAAU,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,cAAc,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3C,YAAY,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACzE,sBAAsB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI,CAAC;CACxE"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { AndroidFirebaseConfig, PushCredentials, PushEnvironment, PushMessage, PushPlatform, } from './PushSignal.nitro.js';
|
|
1
|
+
export type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushEnvironment, PushMessage, PushPlatform, } from './PushSignal.nitro.js';
|
|
2
2
|
export { getCredentials, initialize, onMessage, onNotificationPress, } from './pushSignal';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,YAAY,EACV,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,WAAW,EACX,YAAY,GACb,MAAM,uBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,YAAY,EACV,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,WAAW,EACX,YAAY,GACb,MAAM,uBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AndroidFirebaseConfig, PushCredentials, PushMessage } from './PushSignal.nitro.js';
|
|
1
|
+
import type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushMessage } from './PushSignal.nitro.js';
|
|
2
2
|
export declare function initialize(_config?: AndroidFirebaseConfig): Promise<void>;
|
|
3
3
|
export declare function getCredentials(): Promise<PushCredentials>;
|
|
4
|
-
export declare function onMessage(_listener:
|
|
4
|
+
export declare function onMessage(_listener: OnMessageListener): () => void;
|
|
5
5
|
export declare function onNotificationPress(_listener: (message: PushMessage) => void): () => void;
|
|
6
6
|
//# sourceMappingURL=pushSignal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pushSignal.d.ts","sourceRoot":"","sources":["../../../src/pushSignal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,WAAW,EACZ,MAAM,uBAAoB,CAAC;AAE5B,wBAAsB,UAAU,CAC9B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAAG;AAEnB,wBAAsB,cAAc,IAAI,OAAO,CAAC,eAAe,CAAC,CAE/D;AAED,wBAAgB,SAAS,
|
|
1
|
+
{"version":3,"file":"pushSignal.d.ts","sourceRoot":"","sources":["../../../src/pushSignal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,WAAW,EACZ,MAAM,uBAAoB,CAAC;AAE5B,wBAAsB,UAAU,CAC9B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAAG;AAEnB,wBAAsB,cAAc,IAAI,OAAO,CAAC,eAAe,CAAC,CAE/D;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,iBAAiB,GAAG,MAAM,IAAI,CAElE;AAED,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,GACxC,MAAM,IAAI,CAEZ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AndroidFirebaseConfig, PushCredentials, PushMessage } from './PushSignal.nitro.js';
|
|
1
|
+
import type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushMessage } from './PushSignal.nitro.js';
|
|
2
2
|
export declare function initialize(config?: AndroidFirebaseConfig): Promise<void>;
|
|
3
3
|
export declare function getCredentials(): Promise<PushCredentials>;
|
|
4
|
-
export declare function onMessage(listener:
|
|
4
|
+
export declare function onMessage(listener: OnMessageListener): () => void;
|
|
5
5
|
export declare function onNotificationPress(listener: (message: PushMessage) => void): () => void;
|
|
6
6
|
//# sourceMappingURL=pushSignal.native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pushSignal.native.d.ts","sourceRoot":"","sources":["../../../src/pushSignal.native.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,WAAW,EAEZ,MAAM,uBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"pushSignal.native.d.ts","sourceRoot":"","sources":["../../../src/pushSignal.native.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,WAAW,EAEZ,MAAM,uBAAoB,CAAC;AAmC5B,wBAAgB,UAAU,CAAC,MAAM,GAAE,qBAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5E;AAED,wBAAgB,cAAc,IAAI,OAAO,CAAC,eAAe,CAAC,CAEzD;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,IAAI,CAMjE;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,GACvC,MAAM,IAAI,CAMZ"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include <functional>
|
|
12
|
+
|
|
13
|
+
#include <NitroModules/Promise.hpp>
|
|
14
|
+
#include "PushMessage.hpp"
|
|
15
|
+
#include <functional>
|
|
16
|
+
#include <NitroModules/JNICallable.hpp>
|
|
17
|
+
#include <NitroModules/JPromise.hpp>
|
|
18
|
+
#include "JPushMessage.hpp"
|
|
19
|
+
#include <string>
|
|
20
|
+
#include <optional>
|
|
21
|
+
#include <unordered_map>
|
|
22
|
+
|
|
23
|
+
namespace margelo::nitro::pushsignal {
|
|
24
|
+
|
|
25
|
+
using namespace facebook;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Represents the Java/Kotlin callback `(message: PushMessage) -> Promise<Promise<Boolean>>`.
|
|
29
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
30
|
+
*/
|
|
31
|
+
struct JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage: public jni::JavaClass<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage> {
|
|
32
|
+
public:
|
|
33
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/pushsignal/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage;";
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
/**
|
|
37
|
+
* Invokes the function this `JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage` instance holds through JNI.
|
|
38
|
+
*/
|
|
39
|
+
std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>> invoke(const PushMessage& message) const {
|
|
40
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JPushMessage> /* message */)>("invoke");
|
|
41
|
+
auto __result = method(self(), JPushMessage::fromCpp(message));
|
|
42
|
+
return [&]() {
|
|
43
|
+
auto __promise = Promise<std::shared_ptr<Promise<bool>>>::create();
|
|
44
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
45
|
+
auto __result = jni::static_ref_cast<JPromise::javaobject>(__boxedResult);
|
|
46
|
+
__promise->resolve([&]() {
|
|
47
|
+
auto __promise = Promise<bool>::create();
|
|
48
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
49
|
+
auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
|
|
50
|
+
__promise->resolve(static_cast<bool>(__result->value()));
|
|
51
|
+
});
|
|
52
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
53
|
+
jni::JniException __jniError(__throwable);
|
|
54
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
55
|
+
});
|
|
56
|
+
return __promise;
|
|
57
|
+
}());
|
|
58
|
+
});
|
|
59
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
60
|
+
jni::JniException __jniError(__throwable);
|
|
61
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
62
|
+
});
|
|
63
|
+
return __promise;
|
|
64
|
+
}();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* An implementation of Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage that is backed by a C++ implementation (using `std::function<...>`)
|
|
70
|
+
*/
|
|
71
|
+
class JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx final: public jni::HybridClass<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx, JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage> {
|
|
72
|
+
public:
|
|
73
|
+
static jni::local_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage::javaobject> fromCpp(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>& func) {
|
|
74
|
+
return JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx::newObjectCxxArgs(func);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public:
|
|
78
|
+
/**
|
|
79
|
+
* Invokes the C++ `std::function<...>` this `JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx` instance holds.
|
|
80
|
+
*/
|
|
81
|
+
jni::local_ref<JPromise::javaobject> invoke_cxx(jni::alias_ref<JPushMessage> message) {
|
|
82
|
+
std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>> __result = _func(message->toCpp());
|
|
83
|
+
return [&]() {
|
|
84
|
+
jni::local_ref<JPromise::javaobject> __localPromise = JPromise::create();
|
|
85
|
+
jni::global_ref<JPromise::javaobject> __promise = jni::make_global(__localPromise);
|
|
86
|
+
__result->addOnResolvedListener([=](const std::shared_ptr<Promise<bool>>& __result) {
|
|
87
|
+
__promise->cthis()->resolve([&]() {
|
|
88
|
+
jni::local_ref<JPromise::javaobject> __localPromise = JPromise::create();
|
|
89
|
+
jni::global_ref<JPromise::javaobject> __promise = jni::make_global(__localPromise);
|
|
90
|
+
__result->addOnResolvedListener([=](const bool& __result) {
|
|
91
|
+
__promise->cthis()->resolve(jni::JBoolean::valueOf(__result));
|
|
92
|
+
});
|
|
93
|
+
__result->addOnRejectedListener([=](const std::exception_ptr& __error) {
|
|
94
|
+
auto __jniError = jni::getJavaExceptionForCppException(__error);
|
|
95
|
+
__promise->cthis()->reject(__jniError);
|
|
96
|
+
});
|
|
97
|
+
return __localPromise;
|
|
98
|
+
}());
|
|
99
|
+
});
|
|
100
|
+
__result->addOnRejectedListener([=](const std::exception_ptr& __error) {
|
|
101
|
+
auto __jniError = jni::getJavaExceptionForCppException(__error);
|
|
102
|
+
__promise->cthis()->reject(__jniError);
|
|
103
|
+
});
|
|
104
|
+
return __localPromise;
|
|
105
|
+
}();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public:
|
|
109
|
+
[[nodiscard]]
|
|
110
|
+
inline const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>& getFunction() const {
|
|
111
|
+
return _func;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public:
|
|
115
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/pushsignal/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx;";
|
|
116
|
+
static void registerNatives() {
|
|
117
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx::invoke_cxx)});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private:
|
|
121
|
+
explicit JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>& func): _func(func) { }
|
|
122
|
+
|
|
123
|
+
private:
|
|
124
|
+
friend HybridBase;
|
|
125
|
+
std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)> _func;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
} // namespace margelo::nitro::pushsignal
|
|
@@ -33,10 +33,11 @@ namespace margelo::nitro::pushsignal { struct PushMessage; }
|
|
|
33
33
|
#include "JAndroidFirebaseConfig.hpp"
|
|
34
34
|
#include "PushMessage.hpp"
|
|
35
35
|
#include <functional>
|
|
36
|
-
#include "
|
|
36
|
+
#include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.hpp"
|
|
37
37
|
#include <NitroModules/JNICallable.hpp>
|
|
38
38
|
#include "JPushMessage.hpp"
|
|
39
39
|
#include <unordered_map>
|
|
40
|
+
#include "JFunc_void_PushMessage.hpp"
|
|
40
41
|
|
|
41
42
|
namespace margelo::nitro::pushsignal {
|
|
42
43
|
|
|
@@ -102,9 +103,9 @@ namespace margelo::nitro::pushsignal {
|
|
|
102
103
|
return __promise;
|
|
103
104
|
}();
|
|
104
105
|
}
|
|
105
|
-
void JHybridPushSignalSpec::setOnMessage(const std::function<
|
|
106
|
-
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<
|
|
107
|
-
method(_javaPart,
|
|
106
|
+
void JHybridPushSignalSpec::setOnMessage(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>& callback) {
|
|
107
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage::javaobject> /* callback */)>("setOnMessage_cxx");
|
|
108
|
+
method(_javaPart, JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx::fromCpp(callback));
|
|
108
109
|
}
|
|
109
110
|
void JHybridPushSignalSpec::setOnNotificationPress(const std::function<void(const PushMessage& /* message */)>& callback) {
|
|
110
111
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_PushMessage::javaobject> /* callback */)>("setOnNotificationPress_cxx");
|
|
@@ -56,7 +56,7 @@ namespace margelo::nitro::pushsignal {
|
|
|
56
56
|
// Methods
|
|
57
57
|
std::shared_ptr<Promise<void>> initialize(const AndroidFirebaseConfig& config) override;
|
|
58
58
|
std::shared_ptr<Promise<PushCredentials>> getCredentials() override;
|
|
59
|
-
void setOnMessage(const std::function<
|
|
59
|
+
void setOnMessage(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>& callback) override;
|
|
60
60
|
void setOnNotificationPress(const std::function<void(const PushMessage& /* message */)>& callback) override;
|
|
61
61
|
|
|
62
62
|
private:
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.pushsignal
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.Promise
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents the JavaScript callback `(message: struct) => std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>`.
|
|
17
|
+
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
18
|
+
* or in Kotlin/Java (in which case it is a native callback).
|
|
19
|
+
*/
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
23
|
+
fun interface Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage: (PushMessage) -> Promise<Promise<Boolean>> {
|
|
24
|
+
/**
|
|
25
|
+
* Call the given JS callback.
|
|
26
|
+
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
27
|
+
*/
|
|
28
|
+
@DoNotStrip
|
|
29
|
+
@Keep
|
|
30
|
+
override fun invoke(message: PushMessage): Promise<Promise<Boolean>>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Represents the JavaScript callback `(message: struct) => std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>`.
|
|
35
|
+
* This is implemented in C++, via a `std::function<...>`.
|
|
36
|
+
* The callback might be coming from JS.
|
|
37
|
+
*/
|
|
38
|
+
@DoNotStrip
|
|
39
|
+
@Keep
|
|
40
|
+
@Suppress(
|
|
41
|
+
"KotlinJniMissingFunction", "unused",
|
|
42
|
+
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
43
|
+
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
44
|
+
)
|
|
45
|
+
class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage {
|
|
46
|
+
@DoNotStrip
|
|
47
|
+
@Keep
|
|
48
|
+
private val mHybridData: HybridData
|
|
49
|
+
|
|
50
|
+
@DoNotStrip
|
|
51
|
+
@Keep
|
|
52
|
+
private constructor(hybridData: HybridData) {
|
|
53
|
+
mHybridData = hybridData
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@DoNotStrip
|
|
57
|
+
@Keep
|
|
58
|
+
override fun invoke(message: PushMessage): Promise<Promise<Boolean>>
|
|
59
|
+
= invoke_cxx(message)
|
|
60
|
+
|
|
61
|
+
private external fun invoke_cxx(message: PushMessage): Promise<Promise<Boolean>>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Represents the JavaScript callback `(message: struct) => std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>`.
|
|
66
|
+
* This is implemented in Java/Kotlin, via a `(PushMessage) -> Promise<Promise<Boolean>>`.
|
|
67
|
+
* The callback is always coming from native.
|
|
68
|
+
*/
|
|
69
|
+
@DoNotStrip
|
|
70
|
+
@Keep
|
|
71
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
72
|
+
class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_java(private val function: (PushMessage) -> Promise<Promise<Boolean>>): Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage {
|
|
73
|
+
@DoNotStrip
|
|
74
|
+
@Keep
|
|
75
|
+
override fun invoke(message: PushMessage): Promise<Promise<Boolean>> {
|
|
76
|
+
return this.function(message)
|
|
77
|
+
}
|
|
78
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/HybridPushSignalSpec.kt
CHANGED
|
@@ -38,11 +38,11 @@ abstract class HybridPushSignalSpec: HybridObject() {
|
|
|
38
38
|
@Keep
|
|
39
39
|
abstract fun getCredentials(): Promise<PushCredentials>
|
|
40
40
|
|
|
41
|
-
abstract fun setOnMessage(callback: (message: PushMessage) ->
|
|
41
|
+
abstract fun setOnMessage(callback: (message: PushMessage) -> Promise<Promise<Boolean>>): Unit
|
|
42
42
|
|
|
43
43
|
@DoNotStrip
|
|
44
44
|
@Keep
|
|
45
|
-
private fun setOnMessage_cxx(callback:
|
|
45
|
+
private fun setOnMessage_cxx(callback: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage): Unit {
|
|
46
46
|
val __result = setOnMessage(callback)
|
|
47
47
|
return __result
|
|
48
48
|
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
17
|
|
|
18
18
|
#include "JHybridPushSignalSpec.hpp"
|
|
19
|
+
#include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.hpp"
|
|
19
20
|
#include "JFunc_void_PushMessage.hpp"
|
|
20
21
|
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
21
22
|
|
|
@@ -42,6 +43,7 @@ void registerAllNatives() {
|
|
|
42
43
|
|
|
43
44
|
// Register native JNI methods
|
|
44
45
|
margelo::nitro::pushsignal::JHybridPushSignalSpec::CxxPart::registerNatives();
|
|
46
|
+
margelo::nitro::pushsignal::JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_cxx::registerNatives();
|
|
45
47
|
margelo::nitro::pushsignal::JFunc_void_PushMessage_cxx::registerNatives();
|
|
46
48
|
|
|
47
49
|
// Register Nitro Hybrid Objects
|
|
@@ -38,6 +38,31 @@ namespace margelo::nitro::pushsignal::bridge::swift {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// pragma MARK: std::function<void(bool /* result */)>
|
|
42
|
+
Func_void_bool create_Func_void_bool(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
43
|
+
auto swiftClosure = PushSignal::Func_void_bool::fromUnsafe(swiftClosureWrapper);
|
|
44
|
+
return [swiftClosure = std::move(swiftClosure)](bool result) mutable -> void {
|
|
45
|
+
swiftClosure.call(result);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// pragma MARK: std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>
|
|
50
|
+
Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
51
|
+
auto swiftClosure = PushSignal::Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage::fromUnsafe(swiftClosureWrapper);
|
|
52
|
+
return [swiftClosure = std::move(swiftClosure)](const PushMessage& message) mutable -> std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>> {
|
|
53
|
+
auto __result = swiftClosure.call(message);
|
|
54
|
+
return __result;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// pragma MARK: std::function<void(const std::shared_ptr<Promise<bool>>& /* result */)>
|
|
59
|
+
Func_void_std__shared_ptr_Promise_bool__ create_Func_void_std__shared_ptr_Promise_bool__(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
60
|
+
auto swiftClosure = PushSignal::Func_void_std__shared_ptr_Promise_bool__::fromUnsafe(swiftClosureWrapper);
|
|
61
|
+
return [swiftClosure = std::move(swiftClosure)](const std::shared_ptr<Promise<bool>>& result) mutable -> void {
|
|
62
|
+
swiftClosure.call(result);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
41
66
|
// pragma MARK: std::function<void(const PushMessage& /* message */)>
|
|
42
67
|
Func_void_PushMessage create_Func_void_PushMessage(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
43
68
|
auto swiftClosure = PushSignal::Func_void_PushMessage::fromUnsafe(swiftClosureWrapper);
|
|
@@ -165,6 +165,40 @@ namespace margelo::nitro::pushsignal::bridge::swift {
|
|
|
165
165
|
return Func_void_PushCredentials_Wrapper(std::move(value));
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
// pragma MARK: std::shared_ptr<Promise<bool>>
|
|
169
|
+
/**
|
|
170
|
+
* Specialized version of `std::shared_ptr<Promise<bool>>`.
|
|
171
|
+
*/
|
|
172
|
+
using std__shared_ptr_Promise_bool__ = std::shared_ptr<Promise<bool>>;
|
|
173
|
+
inline std::shared_ptr<Promise<bool>> create_std__shared_ptr_Promise_bool__() noexcept {
|
|
174
|
+
return Promise<bool>::create();
|
|
175
|
+
}
|
|
176
|
+
inline PromiseHolder<bool> wrap_std__shared_ptr_Promise_bool__(std::shared_ptr<Promise<bool>> promise) noexcept {
|
|
177
|
+
return PromiseHolder<bool>(std::move(promise));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// pragma MARK: std::function<void(bool /* result */)>
|
|
181
|
+
/**
|
|
182
|
+
* Specialized version of `std::function<void(bool)>`.
|
|
183
|
+
*/
|
|
184
|
+
using Func_void_bool = std::function<void(bool /* result */)>;
|
|
185
|
+
/**
|
|
186
|
+
* Wrapper class for a `std::function<void(bool / * result * /)>`, this can be used from Swift.
|
|
187
|
+
*/
|
|
188
|
+
class Func_void_bool_Wrapper final {
|
|
189
|
+
public:
|
|
190
|
+
explicit Func_void_bool_Wrapper(std::function<void(bool /* result */)>&& func): _function(std::make_unique<std::function<void(bool /* result */)>>(std::move(func))) {}
|
|
191
|
+
inline void call(bool result) const noexcept {
|
|
192
|
+
_function->operator()(result);
|
|
193
|
+
}
|
|
194
|
+
private:
|
|
195
|
+
std::unique_ptr<std::function<void(bool /* result */)>> _function;
|
|
196
|
+
} SWIFT_NONCOPYABLE;
|
|
197
|
+
Func_void_bool create_Func_void_bool(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
198
|
+
inline Func_void_bool_Wrapper wrap_Func_void_bool(Func_void_bool value) noexcept {
|
|
199
|
+
return Func_void_bool_Wrapper(std::move(value));
|
|
200
|
+
}
|
|
201
|
+
|
|
168
202
|
// pragma MARK: std::unordered_map<std::string, std::string>
|
|
169
203
|
/**
|
|
170
204
|
* Specialized version of `std::unordered_map<std::string, std::string>`.
|
|
@@ -190,6 +224,63 @@ namespace margelo::nitro::pushsignal::bridge::swift {
|
|
|
190
224
|
map.emplace(key, value);
|
|
191
225
|
}
|
|
192
226
|
|
|
227
|
+
// pragma MARK: std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>
|
|
228
|
+
/**
|
|
229
|
+
* Specialized version of `std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage&)>`.
|
|
230
|
+
*/
|
|
231
|
+
using Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage = std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>;
|
|
232
|
+
/**
|
|
233
|
+
* Wrapper class for a `std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& / * message * /)>`, this can be used from Swift.
|
|
234
|
+
*/
|
|
235
|
+
class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_Wrapper final {
|
|
236
|
+
public:
|
|
237
|
+
explicit Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_Wrapper(std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>&& func): _function(std::make_unique<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>>(std::move(func))) {}
|
|
238
|
+
inline std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>> call(PushMessage message) const noexcept {
|
|
239
|
+
auto __result = _function->operator()(message);
|
|
240
|
+
return __result;
|
|
241
|
+
}
|
|
242
|
+
private:
|
|
243
|
+
std::unique_ptr<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>> _function;
|
|
244
|
+
} SWIFT_NONCOPYABLE;
|
|
245
|
+
Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
246
|
+
inline Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_Wrapper wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage(Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage value) noexcept {
|
|
247
|
+
return Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage_Wrapper(std::move(value));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// pragma MARK: std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>
|
|
251
|
+
/**
|
|
252
|
+
* Specialized version of `std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>`.
|
|
253
|
+
*/
|
|
254
|
+
using std__shared_ptr_Promise_std__shared_ptr_Promise_bool____ = std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>;
|
|
255
|
+
inline std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>> create_std__shared_ptr_Promise_std__shared_ptr_Promise_bool____() noexcept {
|
|
256
|
+
return Promise<std::shared_ptr<Promise<bool>>>::create();
|
|
257
|
+
}
|
|
258
|
+
inline PromiseHolder<std::shared_ptr<Promise<bool>>> wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_bool____(std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>> promise) noexcept {
|
|
259
|
+
return PromiseHolder<std::shared_ptr<Promise<bool>>>(std::move(promise));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// pragma MARK: std::function<void(const std::shared_ptr<Promise<bool>>& /* result */)>
|
|
263
|
+
/**
|
|
264
|
+
* Specialized version of `std::function<void(const std::shared_ptr<Promise<bool>>&)>`.
|
|
265
|
+
*/
|
|
266
|
+
using Func_void_std__shared_ptr_Promise_bool__ = std::function<void(const std::shared_ptr<Promise<bool>>& /* result */)>;
|
|
267
|
+
/**
|
|
268
|
+
* Wrapper class for a `std::function<void(const std::shared_ptr<Promise<bool>>& / * result * /)>`, this can be used from Swift.
|
|
269
|
+
*/
|
|
270
|
+
class Func_void_std__shared_ptr_Promise_bool___Wrapper final {
|
|
271
|
+
public:
|
|
272
|
+
explicit Func_void_std__shared_ptr_Promise_bool___Wrapper(std::function<void(const std::shared_ptr<Promise<bool>>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::shared_ptr<Promise<bool>>& /* result */)>>(std::move(func))) {}
|
|
273
|
+
inline void call(std::shared_ptr<Promise<bool>> result) const noexcept {
|
|
274
|
+
_function->operator()(result);
|
|
275
|
+
}
|
|
276
|
+
private:
|
|
277
|
+
std::unique_ptr<std::function<void(const std::shared_ptr<Promise<bool>>& /* result */)>> _function;
|
|
278
|
+
} SWIFT_NONCOPYABLE;
|
|
279
|
+
Func_void_std__shared_ptr_Promise_bool__ create_Func_void_std__shared_ptr_Promise_bool__(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
280
|
+
inline Func_void_std__shared_ptr_Promise_bool___Wrapper wrap_Func_void_std__shared_ptr_Promise_bool__(Func_void_std__shared_ptr_Promise_bool__ value) noexcept {
|
|
281
|
+
return Func_void_std__shared_ptr_Promise_bool___Wrapper(std::move(value));
|
|
282
|
+
}
|
|
283
|
+
|
|
193
284
|
// pragma MARK: std::function<void(const PushMessage& /* message */)>
|
|
194
285
|
/**
|
|
195
286
|
* Specialized version of `std::function<void(const PushMessage&)>`.
|
|
@@ -100,7 +100,7 @@ namespace margelo::nitro::pushsignal {
|
|
|
100
100
|
auto __value = std::move(__result.value());
|
|
101
101
|
return __value;
|
|
102
102
|
}
|
|
103
|
-
inline void setOnMessage(const std::function<
|
|
103
|
+
inline void setOnMessage(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>& callback) override {
|
|
104
104
|
auto __result = _swiftPart.setOnMessage(callback);
|
|
105
105
|
if (__result.hasError()) [[unlikely]] {
|
|
106
106
|
std::rethrow_exception(__result.error());
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ message: PushMessage) -> Promise<Promise<Bool>>` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage {
|
|
15
|
+
public typealias bridge = margelo.nitro.pushsignal.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ message: PushMessage) -> Promise<Promise<Bool>>
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ message: PushMessage) -> Promise<Promise<Bool>>) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(message: PushMessage) -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_bool____ {
|
|
25
|
+
let __result: Promise<Promise<Bool>> = self.closure(message)
|
|
26
|
+
return { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_bool____ in
|
|
27
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_Promise_bool____()
|
|
28
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_bool____(__promise)
|
|
29
|
+
__result
|
|
30
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_Promise_bool__ in
|
|
31
|
+
let __promise = bridge.create_std__shared_ptr_Promise_bool__()
|
|
32
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
|
|
33
|
+
__result
|
|
34
|
+
.then({ __result in __promiseHolder.resolve(__result) })
|
|
35
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
36
|
+
return __promise
|
|
37
|
+
}()) })
|
|
38
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
39
|
+
return __promise
|
|
40
|
+
}()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
45
|
+
* This acquires one additional strong reference on the object!
|
|
46
|
+
*/
|
|
47
|
+
@inline(__always)
|
|
48
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
49
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Casts an unsafe pointer to a `Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage`.
|
|
54
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage>`.
|
|
55
|
+
* This removes one strong reference from the object!
|
|
56
|
+
*/
|
|
57
|
+
@inline(__always)
|
|
58
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage {
|
|
59
|
+
return Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage>.fromOpaque(pointer).takeRetainedValue()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_bool.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ value: Bool) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_bool {
|
|
15
|
+
public typealias bridge = margelo.nitro.pushsignal.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ value: Bool) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ value: Bool) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(value: Bool) -> Void {
|
|
25
|
+
self.closure(value)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_bool`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_bool>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_bool {
|
|
44
|
+
return Unmanaged<Func_void_bool>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__shared_ptr_Promise_bool__.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ value: Promise<Bool>) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_std__shared_ptr_Promise_bool__ {
|
|
15
|
+
public typealias bridge = margelo.nitro.pushsignal.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ value: Promise<Bool>) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ value: Promise<Bool>) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(value: bridge.std__shared_ptr_Promise_bool__) -> Void {
|
|
25
|
+
self.closure({ () -> Promise<Bool> in
|
|
26
|
+
let __promise = Promise<Bool>()
|
|
27
|
+
let __resolver = { (__result: Bool) in
|
|
28
|
+
__promise.resolve(withResult: __result)
|
|
29
|
+
}
|
|
30
|
+
let __rejecter = { (__error: Error) in
|
|
31
|
+
__promise.reject(withError: __error)
|
|
32
|
+
}
|
|
33
|
+
let __resolverCpp = { () -> bridge.Func_void_bool in
|
|
34
|
+
let __closureWrapper = Func_void_bool(__resolver)
|
|
35
|
+
return bridge.create_Func_void_bool(__closureWrapper.toUnsafe())
|
|
36
|
+
}()
|
|
37
|
+
let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
|
|
38
|
+
let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
|
|
39
|
+
return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
|
|
40
|
+
}()
|
|
41
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(value)
|
|
42
|
+
__promiseHolder.addOnResolvedListenerCopy(__resolverCpp)
|
|
43
|
+
__promiseHolder.addOnRejectedListener(__rejecterCpp)
|
|
44
|
+
return __promise
|
|
45
|
+
}())
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
50
|
+
* This acquires one additional strong reference on the object!
|
|
51
|
+
*/
|
|
52
|
+
@inline(__always)
|
|
53
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
54
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Casts an unsafe pointer to a `Func_void_std__shared_ptr_Promise_bool__`.
|
|
59
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_Promise_bool__>`.
|
|
60
|
+
* This removes one strong reference from the object!
|
|
61
|
+
*/
|
|
62
|
+
@inline(__always)
|
|
63
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_Promise_bool__ {
|
|
64
|
+
return Unmanaged<Func_void_std__shared_ptr_Promise_bool__>.fromOpaque(pointer).takeRetainedValue()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -15,7 +15,7 @@ public protocol HybridPushSignalSpec_protocol: HybridObject {
|
|
|
15
15
|
// Methods
|
|
16
16
|
func initialize(config: AndroidFirebaseConfig) throws -> Promise<Void>
|
|
17
17
|
func getCredentials() throws -> Promise<PushCredentials>
|
|
18
|
-
func setOnMessage(callback: @escaping (_ message: PushMessage) ->
|
|
18
|
+
func setOnMessage(callback: @escaping (_ message: PushMessage) -> Promise<Promise<Bool>>) throws -> Void
|
|
19
19
|
func setOnNotificationPress(callback: @escaping (_ message: PushMessage) -> Void) throws -> Void
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -163,12 +163,33 @@ open class HybridPushSignalSpec_cxx {
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
@inline(__always)
|
|
166
|
-
public final func setOnMessage(callback: bridge.
|
|
166
|
+
public final func setOnMessage(callback: bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage) -> bridge.Result_void_ {
|
|
167
167
|
do {
|
|
168
|
-
try self.__implementation.setOnMessage(callback: { () -> (PushMessage) ->
|
|
169
|
-
let __wrappedFunction = bridge.
|
|
170
|
-
return { (__message: PushMessage) ->
|
|
171
|
-
__wrappedFunction.call(__message)
|
|
168
|
+
try self.__implementation.setOnMessage(callback: { () -> (PushMessage) -> Promise<Promise<Bool>> in
|
|
169
|
+
let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage(callback)
|
|
170
|
+
return { (__message: PushMessage) -> Promise<Promise<Bool>> in
|
|
171
|
+
let __result = __wrappedFunction.call(__message)
|
|
172
|
+
return { () -> Promise<Promise<Bool>> in
|
|
173
|
+
let __promise = Promise<Promise<Bool>>()
|
|
174
|
+
let __resolver = { (__result: Promise<Bool>) in
|
|
175
|
+
__promise.resolve(withResult: __result)
|
|
176
|
+
}
|
|
177
|
+
let __rejecter = { (__error: Error) in
|
|
178
|
+
__promise.reject(withError: __error)
|
|
179
|
+
}
|
|
180
|
+
let __resolverCpp = { () -> bridge.Func_void_std__shared_ptr_Promise_bool__ in
|
|
181
|
+
let __closureWrapper = Func_void_std__shared_ptr_Promise_bool__(__resolver)
|
|
182
|
+
return bridge.create_Func_void_std__shared_ptr_Promise_bool__(__closureWrapper.toUnsafe())
|
|
183
|
+
}()
|
|
184
|
+
let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
|
|
185
|
+
let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
|
|
186
|
+
return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
|
|
187
|
+
}()
|
|
188
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_bool____(__result)
|
|
189
|
+
__promiseHolder.addOnResolvedListener(__resolverCpp)
|
|
190
|
+
__promiseHolder.addOnRejectedListener(__rejecterCpp)
|
|
191
|
+
return __promise
|
|
192
|
+
}()
|
|
172
193
|
}
|
|
173
194
|
}())
|
|
174
195
|
return bridge.create_Result_void_()
|
|
@@ -59,7 +59,7 @@ namespace margelo::nitro::pushsignal {
|
|
|
59
59
|
// Methods
|
|
60
60
|
virtual std::shared_ptr<Promise<void>> initialize(const AndroidFirebaseConfig& config) = 0;
|
|
61
61
|
virtual std::shared_ptr<Promise<PushCredentials>> getCredentials() = 0;
|
|
62
|
-
virtual void setOnMessage(const std::function<
|
|
62
|
+
virtual void setOnMessage(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>& callback) = 0;
|
|
63
63
|
virtual void setOnNotificationPress(const std::function<void(const PushMessage& /* message */)>& callback) = 0;
|
|
64
64
|
|
|
65
65
|
protected:
|
package/package.json
CHANGED
package/src/PushSignal.nitro.ts
CHANGED
|
@@ -17,6 +17,10 @@ export interface PushMessage {
|
|
|
17
17
|
data: Record<string, string>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export type OnMessageListener = (
|
|
21
|
+
message: PushMessage
|
|
22
|
+
) => boolean | void | Promise<boolean | void>;
|
|
23
|
+
|
|
20
24
|
export interface AndroidFirebaseConfig {
|
|
21
25
|
project_id?: string;
|
|
22
26
|
mobilesdk_app_id?: string;
|
|
@@ -30,6 +34,6 @@ export interface PushSignal extends HybridObject<{
|
|
|
30
34
|
}> {
|
|
31
35
|
initialize(config: AndroidFirebaseConfig): Promise<void>;
|
|
32
36
|
getCredentials(): Promise<PushCredentials>;
|
|
33
|
-
setOnMessage(callback: (message: PushMessage) =>
|
|
37
|
+
setOnMessage(callback: (message: PushMessage) => Promise<boolean>): void;
|
|
34
38
|
setOnNotificationPress(callback: (message: PushMessage) => void): void;
|
|
35
39
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
2
|
import type {
|
|
3
3
|
AndroidFirebaseConfig,
|
|
4
|
+
OnMessageListener,
|
|
4
5
|
PushCredentials,
|
|
5
6
|
PushMessage,
|
|
6
7
|
PushSignal,
|
|
@@ -9,7 +10,7 @@ import type {
|
|
|
9
10
|
const PushSignalHybridObject =
|
|
10
11
|
NitroModules.createHybridObject<PushSignal>('PushSignal');
|
|
11
12
|
|
|
12
|
-
const messageListeners = new Set<
|
|
13
|
+
const messageListeners = new Set<OnMessageListener>();
|
|
13
14
|
const pressListeners = new Set<(message: PushMessage) => void>();
|
|
14
15
|
let nativeCallbacksBound = false;
|
|
15
16
|
|
|
@@ -20,8 +21,18 @@ function bindNativeCallbacks() {
|
|
|
20
21
|
|
|
21
22
|
nativeCallbacksBound = true;
|
|
22
23
|
|
|
23
|
-
PushSignalHybridObject.setOnMessage((message) => {
|
|
24
|
-
|
|
24
|
+
PushSignalHybridObject.setOnMessage(async (message) => {
|
|
25
|
+
const results = await Promise.all(
|
|
26
|
+
[...messageListeners].map(async (listener) => {
|
|
27
|
+
try {
|
|
28
|
+
return await listener(message);
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return results.some((result) => result === true);
|
|
25
36
|
});
|
|
26
37
|
|
|
27
38
|
PushSignalHybridObject.setOnNotificationPress((message) => {
|
|
@@ -37,9 +48,7 @@ export function getCredentials(): Promise<PushCredentials> {
|
|
|
37
48
|
return PushSignalHybridObject.getCredentials();
|
|
38
49
|
}
|
|
39
50
|
|
|
40
|
-
export function onMessage(
|
|
41
|
-
listener: (message: PushMessage) => void
|
|
42
|
-
): () => void {
|
|
51
|
+
export function onMessage(listener: OnMessageListener): () => void {
|
|
43
52
|
bindNativeCallbacks();
|
|
44
53
|
messageListeners.add(listener);
|
|
45
54
|
return () => {
|
package/src/pushSignal.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AndroidFirebaseConfig,
|
|
3
|
+
OnMessageListener,
|
|
3
4
|
PushCredentials,
|
|
4
5
|
PushMessage,
|
|
5
6
|
} from './PushSignal.nitro';
|
|
@@ -12,9 +13,7 @@ export async function getCredentials(): Promise<PushCredentials> {
|
|
|
12
13
|
throw new Error('Push credentials are not supported on web');
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export function onMessage(
|
|
16
|
-
_listener: (message: PushMessage) => void
|
|
17
|
-
): () => void {
|
|
16
|
+
export function onMessage(_listener: OnMessageListener): () => void {
|
|
18
17
|
return () => {};
|
|
19
18
|
}
|
|
20
19
|
|