native-update-capacitor 0.0.0-stage → 4.4.0

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.
Files changed (140) hide show
  1. package/AI-INTEGRATION-GUIDE.md +578 -0
  2. package/LICENSE +25 -0
  3. package/NativeUpdate.podspec +19 -0
  4. package/README.md +574 -2
  5. package/android/build.gradle +125 -0
  6. package/android/consumer-rules.pro +9 -0
  7. package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
  8. package/android/gradle.properties +17 -0
  9. package/android/manifest-additions.xml +28 -0
  10. package/android/proguard-rules.pro +26 -0
  11. package/android/settings.gradle +2 -0
  12. package/android/src/main/AndroidManifest.xml +13 -0
  13. package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +159 -0
  14. package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +314 -0
  15. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +406 -0
  16. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +48 -0
  17. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +343 -0
  18. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +236 -0
  19. package/android/src/main/java/com/aoneahsan/nativeupdate/JsonOptional.kt +26 -0
  20. package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1249 -0
  21. package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +404 -0
  22. package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +107 -0
  23. package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +240 -0
  24. package/android/variables.gradle +5 -0
  25. package/cli/commands/backend-create.js +623 -0
  26. package/cli/commands/bundle-create.js +145 -0
  27. package/cli/commands/bundle-sign.js +64 -0
  28. package/cli/commands/bundle-verify.js +58 -0
  29. package/cli/commands/flutter-patch.js +107 -0
  30. package/cli/commands/init.js +146 -0
  31. package/cli/commands/keys-generate.js +58 -0
  32. package/cli/commands/monitor.js +89 -0
  33. package/cli/commands/remote-shared.js +264 -0
  34. package/cli/commands/remote.js +634 -0
  35. package/cli/commands/server-start.js +96 -0
  36. package/cli/index.js +625 -0
  37. package/cli/package.json +21 -0
  38. package/dist/esm/app-review/app-review-manager.d.ts +24 -0
  39. package/dist/esm/app-review/app-review-manager.js +194 -0
  40. package/dist/esm/app-review/index.d.ts +5 -0
  41. package/dist/esm/app-review/index.js +5 -0
  42. package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
  43. package/dist/esm/app-review/platform-review-handler.js +137 -0
  44. package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
  45. package/dist/esm/app-review/review-conditions-checker.js +154 -0
  46. package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
  47. package/dist/esm/app-review/review-rate-limiter.js +163 -0
  48. package/dist/esm/app-review/types.d.ts +41 -0
  49. package/dist/esm/app-review/types.js +1 -0
  50. package/dist/esm/app-update/app-update-checker.d.ts +58 -0
  51. package/dist/esm/app-update/app-update-checker.js +227 -0
  52. package/dist/esm/app-update/app-update-installer.d.ts +20 -0
  53. package/dist/esm/app-update/app-update-installer.js +134 -0
  54. package/dist/esm/app-update/app-update-manager.d.ts +28 -0
  55. package/dist/esm/app-update/app-update-manager.js +198 -0
  56. package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
  57. package/dist/esm/app-update/app-update-notifier.js +99 -0
  58. package/dist/esm/app-update/index.d.ts +6 -0
  59. package/dist/esm/app-update/index.js +6 -0
  60. package/dist/esm/app-update/platform-app-update.d.ts +19 -0
  61. package/dist/esm/app-update/platform-app-update.js +138 -0
  62. package/dist/esm/app-update/types.d.ts +58 -0
  63. package/dist/esm/app-update/types.js +11 -0
  64. package/dist/esm/background-update/background-scheduler.d.ts +63 -0
  65. package/dist/esm/background-update/background-scheduler.js +332 -0
  66. package/dist/esm/background-update/index.d.ts +3 -0
  67. package/dist/esm/background-update/index.js +2 -0
  68. package/dist/esm/background-update/notification-manager.d.ts +29 -0
  69. package/dist/esm/background-update/notification-manager.js +88 -0
  70. package/dist/esm/config/support.d.ts +9 -0
  71. package/dist/esm/config/support.js +9 -0
  72. package/dist/esm/core/analytics.d.ts +83 -0
  73. package/dist/esm/core/analytics.js +151 -0
  74. package/dist/esm/core/cache-manager.d.ts +72 -0
  75. package/dist/esm/core/cache-manager.js +274 -0
  76. package/dist/esm/core/config.d.ts +69 -0
  77. package/dist/esm/core/config.js +107 -0
  78. package/dist/esm/core/errors.d.ts +56 -0
  79. package/dist/esm/core/errors.js +85 -0
  80. package/dist/esm/core/event-emitter.d.ts +30 -0
  81. package/dist/esm/core/event-emitter.js +80 -0
  82. package/dist/esm/core/logger.d.ts +21 -0
  83. package/dist/esm/core/logger.js +108 -0
  84. package/dist/esm/core/performance.d.ts +53 -0
  85. package/dist/esm/core/performance.js +153 -0
  86. package/dist/esm/core/plugin-manager.d.ts +88 -0
  87. package/dist/esm/core/plugin-manager.js +224 -0
  88. package/dist/esm/core/security.d.ts +123 -0
  89. package/dist/esm/core/security.js +361 -0
  90. package/dist/esm/core/update-check.d.ts +121 -0
  91. package/dist/esm/core/update-check.js +127 -0
  92. package/dist/esm/definitions.d.ts +872 -0
  93. package/dist/esm/definitions.js +104 -0
  94. package/dist/esm/index.d.ts +14 -0
  95. package/dist/esm/index.js +18 -0
  96. package/dist/esm/live-update/bundle-manager.d.ts +102 -0
  97. package/dist/esm/live-update/bundle-manager.js +344 -0
  98. package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
  99. package/dist/esm/live-update/certificate-pinning.js +77 -0
  100. package/dist/esm/live-update/delta-processor.d.ts +84 -0
  101. package/dist/esm/live-update/delta-processor.js +257 -0
  102. package/dist/esm/live-update/download-manager.d.ts +106 -0
  103. package/dist/esm/live-update/download-manager.js +412 -0
  104. package/dist/esm/live-update/rollout-checker.d.ts +86 -0
  105. package/dist/esm/live-update/rollout-checker.js +304 -0
  106. package/dist/esm/live-update/update-manager.d.ts +63 -0
  107. package/dist/esm/live-update/update-manager.js +321 -0
  108. package/dist/esm/live-update/version-manager.d.ts +93 -0
  109. package/dist/esm/live-update/version-manager.js +390 -0
  110. package/dist/esm/plugin.d.ts +3 -0
  111. package/dist/esm/plugin.js +848 -0
  112. package/dist/esm/security/crypto.d.ts +88 -0
  113. package/dist/esm/security/crypto.js +228 -0
  114. package/dist/esm/security/validator.d.ts +60 -0
  115. package/dist/esm/security/validator.js +142 -0
  116. package/dist/esm/types/app-identity.d.ts +36 -0
  117. package/dist/esm/types/app-identity.js +1 -0
  118. package/dist/esm/types/rollout.d.ts +91 -0
  119. package/dist/esm/types/rollout.js +25 -0
  120. package/dist/esm/web.d.ts +130 -0
  121. package/dist/esm/web.js +981 -0
  122. package/dist/plugin.cjs +1 -0
  123. package/dist/plugin.esm.js +1 -0
  124. package/dist/plugin.js +2 -0
  125. package/docs/CHANGELOG.md +1016 -0
  126. package/docs/KNOWN_LIMITATIONS.md +240 -0
  127. package/docs/MIGRATION.md +391 -0
  128. package/docs/protocol/CLIENT-PROTOCOL.md +199 -0
  129. package/docs/server-requirements.md +211 -0
  130. package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
  131. package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +249 -0
  132. package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +333 -0
  133. package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +464 -0
  134. package/ios/Plugin/Info.plist +43 -0
  135. package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1286 -0
  136. package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
  137. package/ios/Plugin/NativeUpdatePlugin.m +53 -0
  138. package/ios/Plugin/NativeUpdatePlugin.swift +315 -0
  139. package/ios/Plugin/Security/SecurityManager.swift +289 -0
  140. package/package.json +133 -4
@@ -0,0 +1,406 @@
1
+ package com.aoneahsan.nativeupdate
2
+
3
+ import android.app.NotificationChannel
4
+ import android.app.NotificationManager
5
+ import android.app.PendingIntent
6
+ import android.annotation.SuppressLint
7
+ import android.content.Context
8
+ import android.content.Intent
9
+ import android.content.pm.PackageManager
10
+ import android.os.Build
11
+ import androidx.core.app.NotificationCompat
12
+ import androidx.core.app.NotificationManagerCompat
13
+ import androidx.core.content.ContextCompat
14
+ import com.getcapacitor.JSObject
15
+ import com.getcapacitor.Plugin
16
+
17
+ class BackgroundNotificationManager(
18
+ private val context: Context,
19
+ private val eventListener: (String, JSObject) -> Unit
20
+ ) {
21
+
22
+ companion object {
23
+ private const val CHANNEL_ID = "capacitor_native_update"
24
+ private const val CHANNEL_NAME = "App Updates"
25
+ private const val NOTIFICATION_ID = 1001
26
+ // Action strings MUST match NotificationActionReceiver's
27
+ // companion-object constants. They were `UPDATE_NOW` here and
28
+ // `INSTALL_NOW` there, so every action button silently no-op'd.
29
+ private const val ACTION_UPDATE_NOW = NotificationActionReceiver.ACTION_INSTALL_NOW
30
+ private const val ACTION_UPDATE_LATER = NotificationActionReceiver.ACTION_INSTALL_LATER
31
+ private const val ACTION_DISMISS = NotificationActionReceiver.ACTION_DISMISS
32
+
33
+ /**
34
+ * Static method to cancel notification from BroadcastReceiver
35
+ */
36
+ fun cancelNotificationStatic(context: Context) {
37
+ val notificationManager = NotificationManagerCompat.from(context)
38
+ notificationManager.cancel(NOTIFICATION_ID)
39
+ }
40
+ }
41
+
42
+ private var preferences: NotificationPreferences = NotificationPreferences.default()
43
+
44
+ fun createNotificationChannel() {
45
+ val channel = NotificationChannel(
46
+ CHANNEL_ID,
47
+ CHANNEL_NAME,
48
+ NotificationManager.IMPORTANCE_DEFAULT
49
+ ).apply {
50
+ description = "Notifications for app updates"
51
+ enableLights(true)
52
+ enableVibration(true)
53
+ }
54
+
55
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
56
+ notificationManager.createNotificationChannel(channel)
57
+ }
58
+
59
+ fun setPreferences(preferencesData: JSObject) {
60
+ preferences = NotificationPreferences.fromJSObject(preferencesData)
61
+
62
+ // Update channel if preferences changed
63
+ val channelId = preferences.channelId ?: CHANNEL_ID
64
+ val channelName = preferences.channelName ?: CHANNEL_NAME
65
+
66
+ val channel = NotificationChannel(
67
+ channelId,
68
+ channelName,
69
+ getNotificationImportance(preferences.priority)
70
+ ).apply {
71
+ description = "Notifications for app updates"
72
+ enableLights(true)
73
+ enableVibration(preferences.vibrationEnabled)
74
+
75
+ if (!preferences.soundEnabled) {
76
+ setSound(null, null)
77
+ }
78
+ }
79
+
80
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
81
+ notificationManager.createNotificationChannel(channel)
82
+ }
83
+
84
+ fun getPermissionStatus(): NotificationPermissionStatus {
85
+ val notificationManager = NotificationManagerCompat.from(context)
86
+ val areNotificationsEnabled = notificationManager.areNotificationsEnabled()
87
+
88
+ return NotificationPermissionStatus(
89
+ granted = areNotificationsEnabled,
90
+ canRequest = !areNotificationsEnabled,
91
+ shouldShowRationale = false // Android doesn't have this concept
92
+ )
93
+ }
94
+
95
+ fun requestPermissions(): Boolean {
96
+ // On Android 13+, notification permissions need to be requested
97
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
98
+ return ContextCompat.checkSelfPermission(
99
+ context,
100
+ android.Manifest.permission.POST_NOTIFICATIONS
101
+ ) == PackageManager.PERMISSION_GRANTED
102
+ }
103
+
104
+ // For older versions, notifications are enabled by default
105
+ return true
106
+ }
107
+
108
+ @SuppressLint("MissingPermission")
109
+ fun sendUpdateNotification(
110
+ appUpdate: AppUpdateStatus?,
111
+ liveUpdate: LatestVersion?
112
+ ): Boolean {
113
+ if (!getPermissionStatus().granted ||
114
+ (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
115
+ ContextCompat.checkSelfPermission(context, android.Manifest.permission.POST_NOTIFICATIONS) !=
116
+ PackageManager.PERMISSION_GRANTED)
117
+ ) {
118
+ return false
119
+ }
120
+
121
+ val notificationBuilder = createNotificationBuilder(appUpdate, liveUpdate)
122
+
123
+ try {
124
+ val notificationManager = NotificationManagerCompat.from(context)
125
+ notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
126
+
127
+ // Notify listeners
128
+ val eventData = JSObject()
129
+ eventData.put("type", if (appUpdate?.updateAvailable == true) "app_update" else "live_update")
130
+ eventData.put("updateAvailable", true)
131
+ eventData.put("version", appUpdate?.availableVersion ?: liveUpdate?.version ?: "unknown")
132
+ eventData.put("action", "shown")
133
+
134
+ eventListener("backgroundUpdateNotification", eventData)
135
+
136
+ return true
137
+ } catch (_: SecurityException) {
138
+ return false
139
+ }
140
+ }
141
+
142
+ fun cancelNotification() {
143
+ val notificationManager = NotificationManagerCompat.from(context)
144
+ notificationManager.cancel(NOTIFICATION_ID)
145
+ }
146
+
147
+ fun cancelUpdateNotification() {
148
+ cancelNotification()
149
+ }
150
+
151
+ private fun createNotificationBuilder(
152
+ appUpdate: AppUpdateStatus?,
153
+ liveUpdate: LatestVersion?
154
+ ): NotificationCompat.Builder {
155
+ val title = determineTitle(appUpdate, liveUpdate)
156
+ val content = determineContent(appUpdate, liveUpdate)
157
+
158
+ val builder = NotificationCompat.Builder(context, preferences.channelId ?: CHANNEL_ID)
159
+ .setSmallIcon(getNotificationIcon())
160
+ .setContentTitle(title)
161
+ .setContentText(content)
162
+ .setStyle(NotificationCompat.BigTextStyle().bigText(content))
163
+ .setPriority(getNotificationPriority(preferences.priority))
164
+ .setAutoCancel(true)
165
+ .setOnlyAlertOnce(true)
166
+
167
+ // Set sound
168
+ if (preferences.soundEnabled) {
169
+ builder.setDefaults(NotificationCompat.DEFAULT_SOUND)
170
+ }
171
+
172
+ // Set vibration
173
+ if (preferences.vibrationEnabled) {
174
+ builder.setVibrate(longArrayOf(0, 300, 300, 300))
175
+ }
176
+
177
+ // Set content intent (tap action)
178
+ val contentIntent = createContentIntent(appUpdate, liveUpdate)
179
+ builder.setContentIntent(contentIntent)
180
+
181
+ // Add action buttons if enabled
182
+ if (preferences.showActions) {
183
+ addActionButtons(builder, appUpdate, liveUpdate)
184
+ }
185
+
186
+ return builder
187
+ }
188
+
189
+ private fun determineTitle(appUpdate: AppUpdateStatus?, liveUpdate: LatestVersion?): String {
190
+ return when {
191
+ appUpdate?.updateAvailable == true && liveUpdate?.available == true -> "App Updates Available"
192
+ appUpdate?.updateAvailable == true -> "App Update Available"
193
+ liveUpdate?.available == true -> "Content Update Available"
194
+ else -> preferences.title ?: "App Update Available"
195
+ }
196
+ }
197
+
198
+ private fun determineContent(appUpdate: AppUpdateStatus?, liveUpdate: LatestVersion?): String {
199
+ return when {
200
+ appUpdate?.updateAvailable == true && liveUpdate?.available == true ->
201
+ "App version ${appUpdate.availableVersion} and content updates are available"
202
+ appUpdate?.updateAvailable == true ->
203
+ "Version ${appUpdate.availableVersion} is available"
204
+ liveUpdate?.available == true ->
205
+ "New content version ${liveUpdate.version} is available"
206
+ else -> preferences.description ?: "A new version of the app is available"
207
+ }
208
+ }
209
+
210
+ private fun getNotificationIcon(): Int {
211
+ // Try to get custom icon, fallback to default
212
+ return try {
213
+ context.packageManager.getApplicationInfo(context.packageName, 0).icon
214
+ } catch (e: Exception) {
215
+ android.R.drawable.ic_dialog_info
216
+ }
217
+ }
218
+
219
+ private fun getNotificationPriority(priority: NotificationPriority): Int {
220
+ return when (priority) {
221
+ NotificationPriority.MIN -> NotificationCompat.PRIORITY_MIN
222
+ NotificationPriority.LOW -> NotificationCompat.PRIORITY_LOW
223
+ NotificationPriority.DEFAULT -> NotificationCompat.PRIORITY_DEFAULT
224
+ NotificationPriority.HIGH -> NotificationCompat.PRIORITY_HIGH
225
+ NotificationPriority.MAX -> NotificationCompat.PRIORITY_MAX
226
+ }
227
+ }
228
+
229
+ private fun getNotificationImportance(priority: NotificationPriority): Int {
230
+ return when (priority) {
231
+ NotificationPriority.MIN -> NotificationManager.IMPORTANCE_MIN
232
+ NotificationPriority.LOW -> NotificationManager.IMPORTANCE_LOW
233
+ NotificationPriority.DEFAULT -> NotificationManager.IMPORTANCE_DEFAULT
234
+ NotificationPriority.HIGH -> NotificationManager.IMPORTANCE_HIGH
235
+ NotificationPriority.MAX -> NotificationManager.IMPORTANCE_MAX
236
+ }
237
+ }
238
+
239
+ private fun createContentIntent(appUpdate: AppUpdateStatus?, liveUpdate: LatestVersion?): PendingIntent {
240
+ val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
241
+ ?: Intent()
242
+
243
+ intent.putExtra("notification_action", "tapped")
244
+ intent.putExtra("update_type", if (appUpdate?.updateAvailable == true) "app_update" else "live_update")
245
+
246
+ return PendingIntent.getActivity(
247
+ context,
248
+ 0,
249
+ intent,
250
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
251
+ )
252
+ }
253
+
254
+ private fun addActionButtons(
255
+ builder: NotificationCompat.Builder,
256
+ appUpdate: AppUpdateStatus?,
257
+ liveUpdate: LatestVersion?
258
+ ) {
259
+ val actionLabels = preferences.actionLabels ?: ActionLabels.default()
260
+
261
+ // Explicit intents (component set) — Android 8+ blocks implicit
262
+ // broadcasts to non-exported manifest receivers, which silently
263
+ // dropped these notifications before this fix.
264
+ val updateNowIntent = Intent(context, NotificationActionReceiver::class.java).apply {
265
+ action = ACTION_UPDATE_NOW
266
+ putExtra("update_type", if (appUpdate?.updateAvailable == true) "app_update" else "live_update")
267
+ }
268
+ val updateNowPendingIntent = PendingIntent.getBroadcast(
269
+ context,
270
+ 1,
271
+ updateNowIntent,
272
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
273
+ )
274
+
275
+ builder.addAction(
276
+ android.R.drawable.ic_menu_upload,
277
+ actionLabels.updateNow ?: "Update Now",
278
+ updateNowPendingIntent
279
+ )
280
+
281
+ val updateLaterIntent = Intent(context, NotificationActionReceiver::class.java).apply {
282
+ action = ACTION_UPDATE_LATER
283
+ }
284
+ val updateLaterPendingIntent = PendingIntent.getBroadcast(
285
+ context,
286
+ 2,
287
+ updateLaterIntent,
288
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
289
+ )
290
+
291
+ builder.addAction(
292
+ android.R.drawable.ic_menu_recent_history,
293
+ actionLabels.updateLater ?: "Later",
294
+ updateLaterPendingIntent
295
+ )
296
+
297
+ val dismissIntent = Intent(context, NotificationActionReceiver::class.java).apply {
298
+ action = ACTION_DISMISS
299
+ }
300
+ val dismissPendingIntent = PendingIntent.getBroadcast(
301
+ context,
302
+ 3,
303
+ dismissIntent,
304
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
305
+ )
306
+
307
+ builder.addAction(
308
+ android.R.drawable.ic_menu_close_clear_cancel,
309
+ actionLabels.dismiss ?: "Dismiss",
310
+ dismissPendingIntent
311
+ )
312
+ }
313
+ }
314
+
315
+ data class NotificationPreferences(
316
+ val title: String? = null,
317
+ val description: String? = null,
318
+ val iconName: String? = null,
319
+ val soundEnabled: Boolean = true,
320
+ val vibrationEnabled: Boolean = true,
321
+ val showActions: Boolean = true,
322
+ val actionLabels: ActionLabels? = null,
323
+ val channelId: String? = null,
324
+ val channelName: String? = null,
325
+ val priority: NotificationPriority = NotificationPriority.DEFAULT
326
+ ) {
327
+ companion object {
328
+ fun default(): NotificationPreferences {
329
+ return NotificationPreferences(
330
+ title = "App Update Available",
331
+ description = "A new version of the app is available",
332
+ actionLabels = ActionLabels.default()
333
+ )
334
+ }
335
+
336
+ fun fromJSObject(obj: JSObject): NotificationPreferences {
337
+ val actionLabelsObj = obj.getJSObject("actionLabels")
338
+ val priorityString = obj.getString("priority", "default")
339
+
340
+ return NotificationPreferences(
341
+ title = obj.getString("title"),
342
+ description = obj.getString("description"),
343
+ iconName = obj.getString("iconName"),
344
+ soundEnabled = obj.getBoolean("soundEnabled", true) ?: true,
345
+ vibrationEnabled = obj.getBoolean("vibrationEnabled", true) ?: true,
346
+ showActions = obj.getBoolean("showActions", true) ?: true,
347
+ actionLabels = actionLabelsObj?.let { ActionLabels.fromJSObject(it) } ?: ActionLabels.default(),
348
+ channelId = obj.getString("channelId"),
349
+ channelName = obj.getString("channelName"),
350
+ priority = NotificationPriority.fromString(priorityString ?: "default")
351
+ )
352
+ }
353
+ }
354
+ }
355
+
356
+ data class ActionLabels(
357
+ val updateNow: String? = null,
358
+ val updateLater: String? = null,
359
+ val dismiss: String? = null
360
+ ) {
361
+ companion object {
362
+ fun default(): ActionLabels {
363
+ return ActionLabels(
364
+ updateNow = "Update Now",
365
+ updateLater = "Later",
366
+ dismiss = "Dismiss"
367
+ )
368
+ }
369
+
370
+ fun fromJSObject(obj: JSObject): ActionLabels {
371
+ return ActionLabels(
372
+ updateNow = obj.getString("updateNow"),
373
+ updateLater = obj.getString("updateLater"),
374
+ dismiss = obj.getString("dismiss")
375
+ )
376
+ }
377
+ }
378
+ }
379
+
380
+ enum class NotificationPriority(val value: String) {
381
+ MIN("min"),
382
+ LOW("low"),
383
+ DEFAULT("default"),
384
+ HIGH("high"),
385
+ MAX("max");
386
+
387
+ companion object {
388
+ fun fromString(value: String): NotificationPriority {
389
+ return values().find { it.value == value } ?: DEFAULT
390
+ }
391
+ }
392
+ }
393
+
394
+ data class NotificationPermissionStatus(
395
+ val granted: Boolean,
396
+ val canRequest: Boolean,
397
+ val shouldShowRationale: Boolean? = null
398
+ ) {
399
+ fun toJSObject(): JSObject {
400
+ val obj = JSObject()
401
+ obj.put("granted", granted)
402
+ obj.put("canRequest", canRequest)
403
+ shouldShowRationale?.let { obj.put("shouldShowRationale", it) }
404
+ return obj
405
+ }
406
+ }
@@ -0,0 +1,48 @@
1
+ package com.aoneahsan.nativeupdate
2
+
3
+ import java.lang.ref.WeakReference
4
+
5
+ /**
6
+ * Singleton manager to maintain references to plugin instances
7
+ * This allows background workers to access plugin functionality
8
+ */
9
+ object BackgroundUpdateManager {
10
+ @Volatile
11
+ private var backgroundUpdatePlugin: WeakReference<BackgroundUpdatePlugin>? = null
12
+
13
+ @Volatile
14
+ private var liveUpdatePlugin: WeakReference<LiveUpdatePlugin>? = null
15
+
16
+ @Volatile
17
+ private var appUpdatePlugin: WeakReference<AppUpdatePlugin>? = null
18
+
19
+ fun registerBackgroundUpdatePlugin(plugin: BackgroundUpdatePlugin) {
20
+ backgroundUpdatePlugin = WeakReference(plugin)
21
+ }
22
+
23
+ fun registerLiveUpdatePlugin(plugin: LiveUpdatePlugin) {
24
+ liveUpdatePlugin = WeakReference(plugin)
25
+ }
26
+
27
+ fun registerAppUpdatePlugin(plugin: AppUpdatePlugin) {
28
+ appUpdatePlugin = WeakReference(plugin)
29
+ }
30
+
31
+ fun getBackgroundUpdatePlugin(): BackgroundUpdatePlugin? {
32
+ return backgroundUpdatePlugin?.get()
33
+ }
34
+
35
+ fun getLiveUpdatePlugin(): LiveUpdatePlugin? {
36
+ return liveUpdatePlugin?.get()
37
+ }
38
+
39
+ fun getAppUpdatePlugin(): AppUpdatePlugin? {
40
+ return appUpdatePlugin?.get()
41
+ }
42
+
43
+ fun clear() {
44
+ backgroundUpdatePlugin = null
45
+ liveUpdatePlugin = null
46
+ appUpdatePlugin = null
47
+ }
48
+ }