catalyst-core 0.0.3-canary.16 → 0.0.3-canary.17

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 (74) hide show
  1. package/dist/native/androidProject/app/build.gradle.kts +41 -1
  2. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +89 -7
  3. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +213 -3
  4. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/Utils.kt +2 -0
  5. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +7 -0
  6. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationConstants.kt +27 -0
  7. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationUtils.kt +612 -0
  8. package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +158 -0
  9. package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +94 -0
  10. package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +221 -0
  11. package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +378 -0
  12. package/dist/native/androidProject/build.gradle.kts +6 -0
  13. package/dist/native/androidProject/gradle/libs.versions.toml +2 -0
  14. package/dist/native/bridge/WebBridge.js +2 -2
  15. package/dist/native/bridge/constants/NativeInterfaces.js +5 -3
  16. package/dist/native/bridge/hooks.js +18 -3
  17. package/dist/native/bridge/utils/CameraUtils.js +3 -3
  18. package/dist/native/bridge/utils/NativeBridge.js +23 -0
  19. package/dist/native/buildAppAndroid.js +70 -3
  20. package/dist/native/buildAppIos.js +232 -69
  21. package/dist/native/iosnativeWebView/.swiftpm/xcode/xcuserdata/mayansharma.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  22. package/dist/native/iosnativeWebView/Configurations/Debug.xcconfig +3 -0
  23. package/dist/native/iosnativeWebView/Configurations/Release.xcconfig +3 -0
  24. package/dist/native/iosnativeWebView/Configurations/Shared.xcconfig +55 -0
  25. package/dist/native/iosnativeWebView/Package.resolved +158 -0
  26. package/dist/native/iosnativeWebView/Package.swift +26 -0
  27. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/LocalNotificationHandler.swift +293 -0
  28. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/NotificationManager.swift +284 -0
  29. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/PushNotificationHandler.swift +199 -0
  30. package/dist/native/iosnativeWebView/Sources/Core/Constants/CatalystConstants.swift +113 -0
  31. package/dist/native/iosnativeWebView/Sources/Core/Constants/ConfigConstants.swift +22 -0
  32. package/dist/native/iosnativeWebView/Sources/Core/Notifications/NotificationModels.swift +156 -0
  33. package/dist/native/iosnativeWebView/Sources/Core/Protocols/NotificationHandlerProtocol.swift +34 -0
  34. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/BootTimingUtility.swift +2 -2
  35. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/CacheManager.swift +11 -6
  36. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/DeviceInfoUtils.swift +17 -25
  37. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/FrameworkServerUtils.swift +2 -1
  38. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ImageHandler.swift +15 -2
  39. package/dist/native/iosnativeWebView/Sources/Core/Utils/NotificationHandlerProvider.swift +20 -0
  40. package/dist/native/iosnativeWebView/Sources/Core/Utils/NullNotificationHandler.swift +80 -0
  41. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ResourceURLProtocol.swift +17 -10
  42. package/dist/native/iosnativeWebView/Sources/Core/Utils/WebKitConfig.swift +43 -0
  43. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeCommandHandler.swift +619 -0
  44. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/BridgeJavaScriptInterface.swift +8 -0
  45. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/BridgeMessageValidator.swift +75 -3
  46. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/NativeBridge.swift +88 -32
  47. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/SplashView.swift +7 -3
  48. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/SplashViewModel.swift +5 -5
  49. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/WebView.swift +36 -21
  50. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/WebViewModel.swift +13 -11
  51. package/dist/native/iosnativeWebView/iosnativeWebView/AppDelegate.swift +38 -10
  52. package/dist/native/iosnativeWebView/iosnativeWebView/ContentView.swift +5 -2
  53. package/dist/native/iosnativeWebView/iosnativeWebView/Info.plist +11 -0
  54. package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebView.entitlements +8 -0
  55. package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebViewApp.swift +56 -0
  56. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +40 -200
  57. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +127 -1
  58. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcuserdata/mayansharma.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  59. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/xcuserdata/mayansharma.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  60. package/dist/scripts/build.js +1 -1
  61. package/package.json +3 -3
  62. package/caching.js +0 -1
  63. package/dist/native/iosnativeWebView/iosnativeWebView/BridgeCommandHandler.swift +0 -312
  64. package/dist/native/iosnativeWebView/iosnativeWebView/CatalystConstants.swift +0 -91
  65. package/dist/native/iosnativeWebView/iosnativeWebView/ConfigConstants.swift +0 -7
  66. package/index.js +0 -1
  67. package/logger.js +0 -68
  68. package/router.js +0 -1
  69. /package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/CameraTransportUtils.swift +0 -0
  70. /package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/FilePickerHandler.swift +0 -0
  71. /package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/URLWhitelistManager.swift +0 -0
  72. /package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/BridgeDelegateHandler.swift +0 -0
  73. /package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/BridgeFileHandler.swift +0 -0
  74. /package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/WebView}/WebViewNavigationDelegate.swift +0 -0
@@ -15,6 +15,22 @@ val keystorePassword: String? by project.properties // Changed from keyStorePas
15
15
  val keyAlias: String? by project.properties
16
16
  val keyPassword: String? by project.properties
17
17
 
18
+ fun isNotificationsEnabled(): Boolean {
19
+ return try {
20
+ if (configPath == null) return false
21
+ val configFile = File(configPath!!)
22
+ if (!configFile.exists()) return false
23
+
24
+ val json = JSONObject(configFile.readText())
25
+ if (!json.has("WEBVIEW_CONFIG")) return false
26
+
27
+ val webviewConfig = json.getJSONObject("WEBVIEW_CONFIG")
28
+ webviewConfig.optJSONObject("notifications")?.optBoolean("enabled", false) ?: false
29
+ } catch (e: Exception) {
30
+ false
31
+ }
32
+ }
33
+
18
34
  fun getLocalIpAddress(): String {
19
35
  return NetworkInterface.getNetworkInterfaces().toList()
20
36
  .flatMap { it.inetAddresses.toList() }
@@ -129,6 +145,19 @@ android {
129
145
  checkReleaseBuilds = true
130
146
  abortOnError = true
131
147
  }
148
+
149
+ // Conditional source sets based on notifications config
150
+ sourceSets {
151
+ getByName("main") {
152
+ if (isNotificationsEnabled()) {
153
+ logger.info("SourceSet selected: withFcm (notifications enabled)")
154
+ java.srcDirs("src/withFcm/java")
155
+ } else {
156
+ logger.info("SourceSet selected: noFcm (notifications disabled)")
157
+ java.srcDirs("src/noFcm/java")
158
+ }
159
+ }
160
+ }
132
161
  }
133
162
 
134
163
  dependencies {
@@ -147,9 +176,16 @@ dependencies {
147
176
  implementation("io.ktor:ktor-server-netty:3.0.3")
148
177
  implementation("io.ktor:ktor-server-content-negotiation:3.0.3")
149
178
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
150
-
179
+
151
180
  // SLF4J simple logger for Ktor (optional, can be excluded if needed)
152
181
  implementation("org.slf4j:slf4j-simple:2.0.9")
182
+
183
+ // Notification dependencies - conditional based on config
184
+ if (isNotificationsEnabled()) {
185
+ implementation("androidx.localbroadcastmanager:localbroadcastmanager:1.1.0")
186
+ implementation("com.google.firebase:firebase-messaging:23.4.0")
187
+ implementation("com.google.firebase:firebase-analytics:21.5.0")
188
+ }
153
189
  }
154
190
 
155
191
  // Task to verify local IP
@@ -319,6 +355,10 @@ tasks.register("generateWebViewConfig") {
319
355
  }
320
356
  }
321
357
 
358
+ if (isNotificationsEnabled()) {
359
+ apply(plugin = "com.google.gms.google-services")
360
+ }
361
+
322
362
  // Task to create key store if it doesn't exist
323
363
  // Add this task to your build.gradle.kts
324
364
  tasks.register("generateKeystore") {
@@ -1,5 +1,6 @@
1
1
  package io.yourname.androidproject
2
2
 
3
+ import android.content.Intent
3
4
  import android.os.Bundle
4
5
  import android.util.Log
5
6
  import android.view.WindowManager
@@ -10,6 +11,7 @@ import java.util.Properties
10
11
  import io.yourname.androidproject.databinding.ActivityMainBinding
11
12
  import io.yourname.androidproject.NativeBridge
12
13
  import io.yourname.androidproject.utils.KeyboardUtil
14
+ import io.yourname.androidproject.utils.NotificationConstants
13
15
  import kotlinx.coroutines.CoroutineScope
14
16
  import kotlinx.coroutines.MainScope
15
17
  import kotlinx.coroutines.cancelChildren
@@ -20,7 +22,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
20
22
  private lateinit var binding: ActivityMainBinding
21
23
  private lateinit var nativeBridge: NativeBridge
22
24
  private lateinit var customWebView: CustomWebView
23
- private lateinit var properties: Properties
25
+ lateinit var properties: Properties
24
26
  private lateinit var metricsMonitor: MetricsMonitor
25
27
  private lateinit var keyboardUtil: KeyboardUtil
26
28
  private var isHardwareAccelerationEnabled = false
@@ -51,6 +53,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
51
53
 
52
54
  override fun onCreate(savedInstanceState: Bundle?) {
53
55
  super.onCreate(savedInstanceState)
56
+
54
57
  if (BuildConfig.DEBUG) {
55
58
  Log.d(TAG, "📱 onCreate started on thread: ${Thread.currentThread().name}")
56
59
  }
@@ -105,7 +108,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
105
108
 
106
109
  // Clean the cache
107
110
  customWebView.cleanupCache()
108
-
111
+
109
112
  // Setup NativeBridge
110
113
  try {
111
114
  nativeBridge = NativeBridge(this, customWebView.getWebView(), properties)
@@ -127,7 +130,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
127
130
  }
128
131
  })
129
132
 
130
- // Load URL based on environment
133
+ // Load URL based on environment and deep link data
131
134
  try {
132
135
  if (BuildConfig.DEBUG) {
133
136
  // Use the local development server in debug mode
@@ -145,10 +148,17 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
145
148
  currentUrl = "file:///android_asset/build/public/index.html"
146
149
  }
147
150
  }
148
-
149
- // Load URL
150
- customWebView.loadUrl(currentUrl)
151
+
152
+ // Check for notification and handle via /notification endpoint
153
+ if (intent.getBooleanExtra(NotificationConstants.EXTRA_IS_NOTIFICATION, false)) {
154
+ handleNotificationClick(currentUrl, intent)
155
+ } else {
156
+ Log.d(TAG, "🔗 Loading base URL: $currentUrl")
157
+ customWebView.loadUrl(currentUrl)
158
+ }
159
+
151
160
  metricsMonitor.markAppStartComplete()
161
+
152
162
  } catch (e: Exception) {
153
163
  Log.e(TAG, "Failed to load initial URL: ${e.message}")
154
164
  // Fallback to local asset as a last resort
@@ -156,6 +166,19 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
156
166
  }
157
167
  }
158
168
 
169
+ override fun onNewIntent(intent: Intent?) {
170
+ super.onNewIntent(intent)
171
+ // Handle notification click when app is already running
172
+ intent?.let { newIntent ->
173
+ if (newIntent.getBooleanExtra(NotificationConstants.EXTRA_IS_NOTIFICATION, false)) {
174
+ handleNotificationClick(currentUrl, newIntent)
175
+ } else {
176
+ Log.d(TAG, "🔗 onNewIntent - Loading base URL: $currentUrl")
177
+ customWebView.loadUrl(currentUrl)
178
+ }
179
+ }
180
+ }
181
+
159
182
  override fun onSaveInstanceState(outState: Bundle) {
160
183
  super.onSaveInstanceState(outState)
161
184
  try {
@@ -198,9 +221,68 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
198
221
  if (::keyboardUtil.isInitialized) {
199
222
  keyboardUtil.cleanup()
200
223
  }
201
-
224
+ if (::nativeBridge.isInitialized) {
225
+ nativeBridge.cleanup()
226
+ }
202
227
  coroutineContext.cancelChildren()
203
228
  customWebView.destroy()
204
229
  super.onDestroy()
205
230
  }
231
+
232
+ /**
233
+ * Handle notification click by navigating to /notification route
234
+ * Ultra-simple approach: always go to /notification with minimal params
235
+ */
236
+ private fun handleNotificationClick(baseUrl: String, intent: Intent) {
237
+ try {
238
+ val action = intent.getStringExtra(NotificationConstants.EXTRA_ACTION)
239
+ val notificationData = intent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_DATA)
240
+
241
+ Log.d(TAG, "🔔 Handling notification click - Action: ${action ?: "none"}")
242
+
243
+ // Dismiss the notification
244
+ val notificationManager = getSystemService(android.content.Context.NOTIFICATION_SERVICE) as android.app.NotificationManager
245
+ notificationManager.cancelAll() // This dismisses all notifications from this app
246
+
247
+ // Build simple /notification URL
248
+ val url = buildNotificationUrl(baseUrl, action, notificationData)
249
+ Log.d(TAG, "🔔 Navigating to: $url")
250
+
251
+ customWebView.loadUrl(url)
252
+
253
+ } catch (e: Exception) {
254
+ Log.e(TAG, "🔔 Error handling notification click: ${e.message}", e)
255
+ customWebView.loadUrl(baseUrl)
256
+ }
257
+ }
258
+
259
+ /**
260
+ * Build ultra-simple /notification URL
261
+ */
262
+ private fun buildNotificationUrl(baseUrl: String, action: String?, notificationData: String?): String {
263
+ return try {
264
+ val url = StringBuilder("$baseUrl/notification")
265
+ val params = mutableListOf<String>()
266
+
267
+ // Add action if present
268
+ if (!action.isNullOrEmpty()) {
269
+ params.add("action=${java.net.URLEncoder.encode(action, "UTF-8")}")
270
+ }
271
+
272
+ // Add data if present
273
+ if (!notificationData.isNullOrEmpty()) {
274
+ params.add("data=${java.net.URLEncoder.encode(notificationData, "UTF-8")}")
275
+ }
276
+
277
+ if (params.isNotEmpty()) {
278
+ url.append("?").append(params.joinToString("&"))
279
+ }
280
+
281
+ url.toString()
282
+
283
+ } catch (e: Exception) {
284
+ Log.e(TAG, "Error building notification URL: ${e.message}", e)
285
+ "$baseUrl/notification"
286
+ }
287
+ }
206
288
  }
@@ -9,6 +9,7 @@ import android.webkit.JavascriptInterface
9
9
  import android.webkit.WebView
10
10
  import androidx.activity.result.ActivityResultLauncher
11
11
  import androidx.activity.result.contract.ActivityResultContracts
12
+ import androidx.core.app.NotificationCompat
12
13
  import io.yourname.androidproject.MainActivity
13
14
  import io.yourname.androidproject.utils.*
14
15
  import kotlinx.coroutines.*
@@ -104,6 +105,9 @@ class NativeBridge(
104
105
  private lateinit var filePickerLauncher: ActivityResultLauncher<Intent>
105
106
  private var currentFilePickerOptions: FilePickerOptions = FilePickerOptions()
106
107
 
108
+ // Unified notification manager
109
+ private val notificationManager = AppNotificationManager(mainActivity, mainActivity.properties)
110
+
107
111
  companion object {
108
112
  private const val TAG = "NativeBridge"
109
113
 
@@ -170,6 +174,10 @@ class NativeBridge(
170
174
 
171
175
  // Initialize FrameworkServer for large file handling
172
176
  initializeFrameworkServer()
177
+
178
+ // Initialize NotificationManager and set WebView reference
179
+ notificationManager.initialize()
180
+ notificationManager.setWebViewReference(webView)
173
181
  } catch (e: Exception) {
174
182
  BridgeUtils.logError(TAG, "Error initializing NativeBridge", e)
175
183
  }
@@ -274,6 +282,195 @@ class NativeBridge(
274
282
  }
275
283
  }
276
284
  }
285
+
286
+ @JavascriptInterface
287
+ fun scheduleLocalNotification(config: String?) {
288
+ BridgeUtils.safeExecute(webView, BridgeUtils.WebEvents.LOCAL_NOTIFICATION_SCHEDULED, "schedule local notification") {
289
+ mainActivity.runOnUiThread {
290
+ // Parse config with full NotificationConfig support
291
+ val notificationConfig = if (config.isNullOrBlank()) {
292
+ NotificationConfig(title = NotificationConstants.DEFAULT_NOTIFICATION_TITLE, body = NotificationConstants.DEFAULT_NOTIFICATION_BODY)
293
+ } else {
294
+ try {
295
+ val json = org.json.JSONObject(config)
296
+
297
+ // Parse actions array with title and actionId
298
+ val actions = if (json.has("actions")) {
299
+ val actionsArray = json.getJSONArray("actions")
300
+ val actionsList = mutableListOf<NotificationAction>()
301
+ for (i in 0 until actionsArray.length()) {
302
+ val actionObj = actionsArray.getJSONObject(i)
303
+ actionsList.add(
304
+ NotificationAction(
305
+ title = actionObj.getString("title"),
306
+ actionId = actionObj.getString("action")
307
+ )
308
+ )
309
+ }
310
+ actionsList
311
+ } else null
312
+
313
+ // Parse data map if present - support Any type
314
+ val data = if (json.has("data")) {
315
+ val dataObj = json.getJSONObject("data")
316
+ val dataMap = mutableMapOf<String, Any>()
317
+ dataObj.keys().forEach { key ->
318
+ dataMap[key] = dataObj.get(key)
319
+ }
320
+ dataMap
321
+ } else null
322
+
323
+ // Parse style enum if present
324
+ val style = if (json.has("style")) {
325
+ try {
326
+ NotificationStyle.valueOf(json.getString("style"))
327
+ } catch (e: IllegalArgumentException) {
328
+ NotificationStyle.BASIC
329
+ }
330
+ } else NotificationStyle.BASIC
331
+
332
+ NotificationConfig(
333
+ title = json.optString("title", NotificationConstants.DEFAULT_NOTIFICATION_TITLE),
334
+ body = json.optString("body", NotificationConstants.DEFAULT_NOTIFICATION_BODY),
335
+ channel = json.optString("channel", NotificationConstants.DEFAULT_CHANNEL_ID),
336
+ badge = if (json.has("badge")) json.getInt("badge") else null,
337
+ actions = actions,
338
+ largeImage = json.optString("largeImage", null),
339
+ style = style,
340
+ priority = json.optInt("priority", NotificationCompat.PRIORITY_DEFAULT),
341
+ vibrate = json.optBoolean("vibrate", true),
342
+ autoCancel = json.optBoolean("autoCancel", true),
343
+ ongoing = json.optBoolean("ongoing", false),
344
+ data = data
345
+ )
346
+ } catch (e: Exception) {
347
+ BridgeUtils.logError(TAG, "Error parsing notification config", e)
348
+ NotificationConfig(title = NotificationConstants.DEFAULT_NOTIFICATION_TITLE, body = NotificationConstants.DEFAULT_NOTIFICATION_BODY)
349
+ }
350
+ }
351
+
352
+ val notificationId = notificationManager.scheduleLocal(notificationConfig)
353
+ BridgeUtils.notifyWeb(webView, BridgeUtils.WebEvents.LOCAL_NOTIFICATION_SCHEDULED,
354
+ """{"notificationId": "$notificationId", "scheduled": true}""")
355
+ }
356
+ }
357
+ }
358
+
359
+ @JavascriptInterface
360
+ fun cancelLocalNotification(notificationId: String?) {
361
+ BridgeUtils.safeExecute(webView, BridgeUtils.WebEvents.LOCAL_NOTIFICATION_SCHEDULED, "cancel local notification") {
362
+ mainActivity.runOnUiThread {
363
+ val success = notificationManager.cancelLocal(notificationId)
364
+ BridgeUtils.notifyWeb(webView, BridgeUtils.WebEvents.LOCAL_NOTIFICATION_SCHEDULED,
365
+ """{"notificationId": "$notificationId", "cancelled": $success}""")
366
+ }
367
+ }
368
+ }
369
+
370
+ @JavascriptInterface
371
+ fun requestNotificationPermission(config: String?) {
372
+ BridgeUtils.safeExecute(webView, BridgeUtils.WebEvents.NOTIFICATION_PERMISSION_STATUS, "request notification permission") {
373
+ mainActivity.runOnUiThread {
374
+ notificationManager.requestPermission(mainActivity) { granted ->
375
+ val status = if (granted) "GRANTED" else "DENIED"
376
+ BridgeUtils.notifyWeb(webView, BridgeUtils.WebEvents.NOTIFICATION_PERMISSION_STATUS, status)
377
+ }
378
+ }
379
+ }
380
+ }
381
+
382
+ @JavascriptInterface
383
+ fun registerForPushNotifications(config: String?) {
384
+ BridgeUtils.safeExecute(webView, BridgeUtils.WebEvents.PUSH_NOTIFICATION_TOKEN, "register for push notifications") {
385
+ mainActivity.runOnUiThread {
386
+ launch {
387
+ try {
388
+ val token = notificationManager.initializePush()
389
+ BridgeUtils.notifyWeb(webView, BridgeUtils.WebEvents.PUSH_NOTIFICATION_TOKEN,
390
+ """{"token": "$token", "registered": true}""")
391
+ } catch (e: Exception) {
392
+ BridgeUtils.notifyWebError(webView, BridgeUtils.WebEvents.PUSH_NOTIFICATION_TOKEN,
393
+ "Push registration failed: ${e.message}")
394
+ }
395
+ }
396
+ }
397
+ }
398
+ }
399
+
400
+
401
+ @JavascriptInterface
402
+ fun subscribeToTopic(config: String?) {
403
+ BridgeUtils.safeExecute(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED, "subscribe to topic") {
404
+ mainActivity.runOnUiThread {
405
+ launch {
406
+ try {
407
+ val json = org.json.JSONObject(config ?: "{}")
408
+ val topic = json.optString("topic", "")
409
+
410
+ if (topic.isBlank()) {
411
+ BridgeUtils.notifyWebError(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED,
412
+ "Topic name cannot be empty")
413
+ return@launch
414
+ }
415
+
416
+ val success = notificationManager.subscribeToTopic(topic)
417
+ BridgeUtils.notifyWeb(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED,
418
+ """{"topic": "$topic", "subscribed": $success}""")
419
+
420
+ } catch (e: Exception) {
421
+ BridgeUtils.notifyWebError(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED,
422
+ "Topic subscription failed: ${e.message}")
423
+ }
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ @JavascriptInterface
430
+ fun unsubscribeFromTopic(config: String?) {
431
+ BridgeUtils.safeExecute(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED, "unsubscribe from topic") {
432
+ mainActivity.runOnUiThread {
433
+ launch {
434
+ try {
435
+ val json = org.json.JSONObject(config ?: "{}")
436
+ val topic = json.optString("topic", "")
437
+
438
+ if (topic.isBlank()) {
439
+ BridgeUtils.notifyWebError(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED,
440
+ "Topic name cannot be empty")
441
+ return@launch
442
+ }
443
+
444
+ val success = notificationManager.unsubscribeFromTopic(topic)
445
+ BridgeUtils.notifyWeb(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED,
446
+ """{"topic": "$topic", "unsubscribed": $success}""")
447
+
448
+ } catch (e: Exception) {
449
+ BridgeUtils.notifyWebError(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED,
450
+ "Topic unsubscription failed: ${e.message}")
451
+ }
452
+ }
453
+ }
454
+ }
455
+ }
456
+
457
+ @JavascriptInterface
458
+ fun getSubscribedTopics(config: String?) {
459
+ BridgeUtils.safeExecute(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED, "get subscribed topics") {
460
+ mainActivity.runOnUiThread {
461
+ try {
462
+ val topics = notificationManager.getSubscribedTopics()
463
+ val topicsArray = org.json.JSONArray(topics.toList())
464
+ BridgeUtils.notifyWeb(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED,
465
+ """{"topics": $topicsArray}""")
466
+
467
+ } catch (e: Exception) {
468
+ BridgeUtils.notifyWebError(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED,
469
+ "Failed to get subscribed topics: ${e.message}")
470
+ }
471
+ }
472
+ }
473
+ }
277
474
 
278
475
  private fun initializeCameraLauncher() {
279
476
  cameraLauncher = mainActivity.registerForActivityResult(ActivityResultContracts.TakePicture()) { success ->
@@ -556,19 +753,32 @@ class NativeBridge(
556
753
 
557
754
  // Removed getFileSize - now handled by FileUtils.getFileSize
558
755
 
756
+ /**
757
+ * Handle permission request results
758
+ */
759
+ fun handlePermissionResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
760
+ BridgeUtils.safeExecute(webView, BridgeUtils.WebEvents.NOTIFICATION_PERMISSION_STATUS, "handle permission result") {
761
+ // Delegate to notification manager which handles notification permissions
762
+ notificationManager.getNotificationUtils().handlePermissionResult(requestCode, permissions, grantResults)
763
+ }
764
+ }
765
+
559
766
  /**
560
767
  * Cleanup method to be called when the bridge is being destroyed
561
768
  */
562
769
  fun cleanup() {
563
770
  BridgeUtils.logDebug(TAG, "Cleaning up NativeBridge resources")
564
-
771
+
565
772
  try {
773
+ // Cleanup NotificationManager
774
+ notificationManager.cleanup()
775
+
566
776
  // Stop FrameworkServer
567
777
  FrameworkServerUtils.stopServer()
568
-
778
+
569
779
  // Cancel any pending coroutines
570
780
  supervisorJob.cancel()
571
-
781
+
572
782
  BridgeUtils.logInfo(TAG, "NativeBridge cleanup completed")
573
783
  } catch (e: Exception) {
574
784
  BridgeUtils.logError(TAG, "Error during NativeBridge cleanup", e)
@@ -3,6 +3,8 @@ package io.yourname.androidproject
3
3
  import android.net.Uri
4
4
 
5
5
  fun isUrlAllowed(url: String, allowedUrls: List<String>): Boolean {
6
+ // TODO: temp
7
+ return true
6
8
  // Always allow framework server URLs (localhost with /framework- pattern)
7
9
  // These are internal infrastructure URLs used for large file handling
8
10
  // Use strict regex to prevent bypass attacks
@@ -53,6 +53,13 @@ object BridgeUtils {
53
53
  // Device info events
54
54
  ON_DEVICE_INFO_SUCCESS("ON_DEVICE_INFO_SUCCESS"),
55
55
  ON_DEVICE_INFO_ERROR("ON_DEVICE_INFO_ERROR"),
56
+
57
+ // Notification events
58
+ NOTIFICATION_PERMISSION_STATUS("NOTIFICATION_PERMISSION_STATUS"),
59
+ LOCAL_NOTIFICATION_SCHEDULED("LOCAL_NOTIFICATION_SCHEDULED"),
60
+ PUSH_NOTIFICATION_TOKEN("PUSH_NOTIFICATION_TOKEN"),
61
+ NOTIFICATION_RECEIVED("NOTIFICATION_RECEIVED"),
62
+ NOTIFICATION_ACTION_PERFORMED("NOTIFICATION_ACTION_PERFORMED"),
56
63
  }
57
64
 
58
65
  /**
@@ -0,0 +1,27 @@
1
+ package io.yourname.androidproject.utils
2
+
3
+ /**
4
+ * Constants for notification channels
5
+ */
6
+ object NotificationConstants {
7
+ // Channel IDs
8
+ const val DEFAULT_CHANNEL_ID = "default"
9
+ const val URGENT_CHANNEL_ID = "urgent"
10
+
11
+ // Channel names
12
+ const val DEFAULT_CHANNEL_NAME = "Notifications"
13
+ const val URGENT_CHANNEL_NAME = "Urgent Notifications"
14
+
15
+ // Channel descriptions
16
+ const val DEFAULT_CHANNEL_DESCRIPTION = "General notifications"
17
+ const val URGENT_CHANNEL_DESCRIPTION = "Urgent notifications that require immediate attention"
18
+
19
+ // Default notification messages
20
+ const val DEFAULT_NOTIFICATION_TITLE = "Notification"
21
+ const val DEFAULT_NOTIFICATION_BODY = "You have a new message"
22
+
23
+ // Intent extras
24
+ const val EXTRA_IS_NOTIFICATION = "is_notification"
25
+ const val EXTRA_ACTION = "action"
26
+ const val EXTRA_NOTIFICATION_DATA = "notification_data"
27
+ }