catalyst-core 0.0.3-canary.9 → 0.1.0-beta.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 +4 -5
- package/bin/catalyst.js +28 -15
- package/changelog.md +139 -30
- package/dist/native/androidProject/app/build.gradle.kts +125 -15
- package/dist/native/androidProject/app/proguard-rules.pro +85 -14
- package/dist/native/androidProject/app/src/debug/res/xml/network_security_config.xml +8 -0
- package/dist/native/androidProject/app/src/main/AndroidManifest.xml +10 -3
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/BridgeMessageValidator.kt +552 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CatalystConstants.kt +109 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +605 -124
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +405 -47
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MetricsMonitor.kt +341 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +954 -71
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/SplashActivity.kt +111 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/URLWhitelistManager.kt +231 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/Utils.kt +49 -55
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/WebCacheManager.kt +81 -8
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/design/DesignTokens.kt +307 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/EmulatorDetector.kt +203 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/FridaDetector.kt +187 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityAlertHandler.kt +170 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityAlertUI.kt +366 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityBottomSheet.kt +138 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityCheckManager.kt +511 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityCheckScheduler.kt +68 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +47 -11
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DeviceInfoUtils.kt +38 -13
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DownloadUtils.kt +36 -14
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FileUtils.kt +3 -2
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FrameworkServerUtils.kt +57 -8
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/IntentUtils.kt +31 -6
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/KeyboardUtil.kt +82 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NetworkUtils.kt +105 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationConstants.kt +28 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationUtils.kt +639 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/SafeAreaUtils.kt +62 -0
- package/dist/native/androidProject/app/src/main/res/drawable/splashscreen_fallback.png +0 -0
- package/dist/native/androidProject/app/src/main/res/layout/activity_main.xml +1 -0
- package/dist/native/androidProject/app/src/main/res/layout/activity_splash.xml +20 -0
- package/dist/native/androidProject/app/src/main/res/values/themes.xml +23 -0
- package/dist/native/androidProject/app/src/main/res/values-night/themes.xml +11 -0
- package/dist/native/androidProject/app/src/main/res/xml/network_security_config.xml +12 -0
- package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +166 -0
- package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +94 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeMessageValidatorTest.kt +267 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeUtilsTest.kt +286 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CameraUtilsTest.kt +296 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/ConfigMappingTest.kt +594 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CustomWebviewTest.kt +466 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/DeviceInfoUtilsTest.kt +187 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FileUtilsTest.kt +304 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NativeBridgeTest.kt +424 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NotificationUtilsTest.kt +469 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/SecurityBridgeTest.kt +199 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/URLWhitelistManagerTest.kt +462 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/WebCacheManagerTest.kt +391 -0
- package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +224 -0
- package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +399 -0
- package/dist/native/androidProject/build.gradle.kts +6 -0
- package/dist/native/androidProject/gradle/libs.versions.toml +8 -2
- package/dist/native/androidSetup.js +4 -3
- package/dist/native/assets/catalyst.png +0 -0
- package/dist/native/bridge/WebBridge.js +16 -3
- package/dist/native/bridge/constants/NativeInterfaces.js +28 -10
- package/dist/native/bridge/errors.js +1 -1
- package/dist/native/bridge/hooks.js +76 -16
- package/dist/native/bridge/safeArea.js +5 -0
- package/dist/native/bridge/standardizedHooks.js +23 -5
- package/dist/native/bridge/useBaseHook.js +7 -9
- package/dist/native/bridge/utils/CameraUtils.js +58 -0
- package/dist/native/bridge/utils/FileObjectConverter.js +40 -0
- package/dist/native/bridge/utils/NativeBridge.js +57 -8
- package/dist/native/buildAppAndroid.js +115 -43
- package/dist/native/buildAppIos.js +291 -26
- package/dist/native/iosnativeWebView/Configurations/Debug.xcconfig +21 -0
- package/dist/native/iosnativeWebView/Configurations/Release.xcconfig +24 -0
- package/dist/native/iosnativeWebView/Configurations/Shared.xcconfig +50 -0
- package/dist/native/iosnativeWebView/Package.resolved +32 -0
- package/dist/native/iosnativeWebView/Package.swift +37 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/LocalNotificationHandler.swift +293 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/NotificationManager.swift +299 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/PushNotificationHandler.swift +199 -0
- package/dist/native/iosnativeWebView/Sources/Core/Constants/CatalystConstants.swift +125 -0
- package/dist/native/iosnativeWebView/Sources/Core/Constants/ConfigConstants.swift +70 -0
- package/dist/native/iosnativeWebView/Sources/Core/Notifications/NotificationModels.swift +156 -0
- package/dist/native/iosnativeWebView/Sources/Core/Protocols/NotificationHandlerProtocol.swift +35 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/BootTimingUtility.swift +26 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/CacheManager.swift +69 -36
- package/dist/native/iosnativeWebView/Sources/Core/Utils/CameraTransportUtils.swift +363 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/DeviceInfoUtils.swift +67 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/FilePickerHandler.swift +1053 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/FrameworkServerUtils.swift +901 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ImageHandler.swift +206 -20
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NetworkMonitor.swift +112 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NotificationHandlerProvider.swift +20 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NullNotificationHandler.swift +85 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ResourceURLProtocol.swift +60 -25
- package/dist/native/iosnativeWebView/Sources/Core/Utils/SafeAreaUtils.swift +132 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/ScreenSecureManager.swift +131 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/URLWhitelistManager.swift +224 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/WebKitConfig.swift +43 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeCommandHandler.swift +991 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeDelegateHandler.swift +166 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +340 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeJavaScriptInterface.swift +149 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +611 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +334 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashView.swift +95 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashViewModel.swift +86 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +181 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewModel.swift +182 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +395 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/AppDelegate.swift +84 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/AccentColor.colorset/Contents.json +8 -8
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/AppIcon.appiconset/Contents.json +10 -10
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/Contents.json +4 -4
- package/dist/native/iosnativeWebView/iosnativeWebView/ContentView.swift +65 -10
- package/dist/native/iosnativeWebView/iosnativeWebView/Info-Release.plist +21 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Info.plist +13 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Preview Content/Preview Assets.xcassets/Contents.json +4 -4
- package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebView.entitlements +12 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebViewApp.swift +80 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/localhost.p12 +0 -0
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +118 -100
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +69 -0
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/xcshareddata/xcschemes/iosnativeWebView.xcscheme +9 -4
- package/dist/native/iosnativeWebView/iosnativeWebView.xctestplan +47 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BootTimingUtilityTests.swift +236 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeCommandHandlerSecurityTests.swift +212 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +418 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/CacheManagerTests.swift +390 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/ConfigMappingTests.swift +299 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/FilePickerHandlerTests.swift +383 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/FrameworkServerUtilsTests.swift +391 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/NativeBridgeTests.swift +581 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/NotificationHandlerTests.swift +430 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/ScreenSecureManagerTests.swift +121 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/URLWhitelistManagerTests.swift +367 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/WebViewTests.swift +440 -0
- package/dist/native/renameAndroidProject.js +80 -70
- package/dist/native/setupEmulatorIos.js +22 -5
- package/dist/native/setupServer.js +11 -10
- package/dist/native/terminalProgress.js +10 -10
- package/dist/native/utils.js +4 -5
- package/dist/otel.js +4 -0
- package/dist/scripts/build.js +2 -2
- package/dist/scripts/devBuild.js +2 -2
- package/dist/scripts/loadEnvironmentVariables.js +3 -1
- package/dist/scripts/scriptUtils.js +2 -2
- package/dist/sentry.js +4 -1
- package/dist/server/renderer/document/Body.js +4 -4
- package/dist/server/renderer/handler.js +7 -5
- package/dist/webpack/development.client.babel.js +1 -1
- package/mcp_v2/conversion-tasks.json +326 -0
- package/mcp_v2/knowledge-base.json +1068 -0
- package/mcp_v2/lib/helpers.js +165 -0
- package/mcp_v2/mcp.js +563 -0
- package/mcp_v2/package.json +13 -0
- package/mcp_v2/schema.sql +88 -0
- package/mcp_v2/setup.js +278 -0
- package/mcp_v2/tools/build.js +686 -0
- package/mcp_v2/tools/config.js +453 -0
- package/mcp_v2/tools/conversion.js +799 -0
- package/mcp_v2/tools/debug.js +113 -0
- package/mcp_v2/tools/knowledge.js +219 -0
- package/mcp_v2/tools/sync.js +23 -0
- package/mcp_v2/tools/tasks.js +945 -0
- package/package.json +11 -15
- package/dist/native/androidProject/.idea/.name +0 -1
- package/dist/native/androidProject/.idea/AndroidProjectSystem.xml +0 -6
- package/dist/native/androidProject/.idea/compiler.xml +0 -6
- package/dist/native/androidProject/.idea/deploymentTargetSelector.xml +0 -10
- package/dist/native/androidProject/.idea/gradle.xml +0 -18
- package/dist/native/androidProject/.idea/migrations.xml +0 -10
- package/dist/native/androidProject/.idea/misc.xml +0 -10
- package/dist/native/androidProject/.idea/runConfigurations.xml +0 -17
- package/dist/native/androidProject/.idea/vcs.xml +0 -6
- package/dist/native/iosnativeWebView/iosnativeWebView/NativeBridge.swift +0 -217
- package/dist/native/iosnativeWebView/iosnativeWebView/WebView.swift +0 -96
- package/dist/native/iosnativeWebView/iosnativeWebView/WebViewModel.swift +0 -47
- package/dist/native/iosnativeWebView/iosnativeWebView/WebViewNavigationDelegate.swift +0 -140
- package/license +0 -10
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
package io.yourname.androidproject.utils
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.Intent
|
|
5
|
+
import android.webkit.WebView
|
|
6
|
+
import androidx.core.app.NotificationCompat
|
|
7
|
+
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
|
8
|
+
import org.json.JSONObject
|
|
9
|
+
import org.json.JSONArray
|
|
10
|
+
import java.util.Properties
|
|
11
|
+
import com.google.firebase.messaging.FirebaseMessaging
|
|
12
|
+
import com.google.firebase.messaging.FirebaseMessagingService
|
|
13
|
+
import com.google.firebase.messaging.RemoteMessage
|
|
14
|
+
import com.google.android.gms.tasks.OnCompleteListener
|
|
15
|
+
import com.google.android.gms.common.ConnectionResult
|
|
16
|
+
import com.google.android.gms.common.GoogleApiAvailability
|
|
17
|
+
import kotlinx.coroutines.TimeoutCancellationException
|
|
18
|
+
import kotlinx.coroutines.withTimeout
|
|
19
|
+
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
20
|
+
import kotlin.coroutines.resume
|
|
21
|
+
import kotlin.coroutines.resumeWithException
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Firebase Cloud Messaging Service and Utility
|
|
25
|
+
* Handles FCM callbacks, token management, topic subscription, and message processing
|
|
26
|
+
*/
|
|
27
|
+
class PushNotificationUtils(private val properties: Properties = Properties()) : FirebaseMessagingService() {
|
|
28
|
+
|
|
29
|
+
companion object {
|
|
30
|
+
private const val TAG = "PushNotificationUtils"
|
|
31
|
+
private const val PREFS_NAME = "push_notifications"
|
|
32
|
+
private const val KEY_PUSH_TOKEN = "push_token"
|
|
33
|
+
private const val KEY_SUBSCRIBED_TOPICS = "subscribed_topics"
|
|
34
|
+
private const val PROVIDER_FCM = "fcm"
|
|
35
|
+
|
|
36
|
+
// Broadcast actions
|
|
37
|
+
const val ACTION_MESSAGE_RECEIVED = "io.yourname.androidproject.PUSH_MESSAGE_RECEIVED"
|
|
38
|
+
const val ACTION_TOKEN_REFRESHED = "io.yourname.androidproject.PUSH_TOKEN_REFRESHED"
|
|
39
|
+
const val EXTRA_MESSAGE_DATA = "message_data"
|
|
40
|
+
const val EXTRA_TOKEN = "token"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ==================== FIREBASE MESSAGING SERVICE CALLBACKS ====================
|
|
44
|
+
|
|
45
|
+
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
|
46
|
+
super.onMessageReceived(remoteMessage)
|
|
47
|
+
|
|
48
|
+
BridgeUtils.logInfo(TAG, "FCM message received from: ${remoteMessage.from}")
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
// Convert RemoteMessage to data map
|
|
52
|
+
val data = mutableMapOf<String, String>()
|
|
53
|
+
|
|
54
|
+
// Add notification data if present
|
|
55
|
+
remoteMessage.notification?.let { notification ->
|
|
56
|
+
notification.title?.let { data["title"] = it }
|
|
57
|
+
notification.body?.let { data["body"] = it }
|
|
58
|
+
notification.channelId?.let { data["channel"] = it }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Add custom data
|
|
62
|
+
data.putAll(remoteMessage.data)
|
|
63
|
+
|
|
64
|
+
// Send broadcast to notify activity about the message
|
|
65
|
+
sendMessageReceivedBroadcast(this, data)
|
|
66
|
+
|
|
67
|
+
} catch (e: Exception) {
|
|
68
|
+
BridgeUtils.logError(TAG, "Error processing FCM message", e)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
override fun onNewToken(token: String) {
|
|
73
|
+
super.onNewToken(token)
|
|
74
|
+
|
|
75
|
+
BridgeUtils.logInfo(TAG, "FCM token refreshed: ${token.take(20)}...")
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
storePushToken(this, token)
|
|
79
|
+
sendTokenRefreshedBroadcast(this, token)
|
|
80
|
+
|
|
81
|
+
} catch (e: Exception) {
|
|
82
|
+
BridgeUtils.logError(TAG, "Error handling token refresh", e)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ==================== UTILITY METHODS ====================
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Initialize and get FCM token
|
|
90
|
+
*/
|
|
91
|
+
suspend fun initializeAndGetToken(context: Context): String {
|
|
92
|
+
val enabled = properties.getProperty("notifications.enabled", "true").toBoolean()
|
|
93
|
+
if (!enabled) {
|
|
94
|
+
BridgeUtils.logInfo(TAG, "Push notifications disabled")
|
|
95
|
+
return ""
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return try {
|
|
99
|
+
val token = withTimeout(30_000) {
|
|
100
|
+
suspendCancellableCoroutine<String> { continuation ->
|
|
101
|
+
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
|
|
102
|
+
if (continuation.isCompleted) return@OnCompleteListener
|
|
103
|
+
|
|
104
|
+
if (!task.isSuccessful) {
|
|
105
|
+
val message = task.exception?.message ?: "Fetching FCM registration token failed"
|
|
106
|
+
continuation.resumeWithException(IllegalStateException(message))
|
|
107
|
+
return@OnCompleteListener
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
val result = task.result
|
|
111
|
+
if (result.isNullOrBlank()) {
|
|
112
|
+
continuation.resumeWithException(IllegalStateException("FCM token retrieval returned empty result"))
|
|
113
|
+
} else {
|
|
114
|
+
continuation.resume(result)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
storePushToken(context, token)
|
|
121
|
+
BridgeUtils.logInfo(TAG, "FCM token retrieved: ${token.take(20)}...")
|
|
122
|
+
token
|
|
123
|
+
} catch (e: TimeoutCancellationException) {
|
|
124
|
+
val timeoutError = "FCM token request timed out after 30 seconds. Check network connectivity and Firebase configuration."
|
|
125
|
+
BridgeUtils.logError(TAG, timeoutError, e)
|
|
126
|
+
throw Exception(timeoutError, e)
|
|
127
|
+
} catch (e: Exception) {
|
|
128
|
+
BridgeUtils.logError(TAG, "Failed to get FCM token", e)
|
|
129
|
+
throw e
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Handle incoming push notification (called from broadcast receiver)
|
|
135
|
+
*/
|
|
136
|
+
fun handleIncomingPush(webView: WebView?, context: Context, data: Map<String, String>) {
|
|
137
|
+
BridgeUtils.logInfo(TAG, "Processing incoming push notification")
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
val payload = data["payload"]?.let { JSONObject(it) } ?: JSONObject().apply {
|
|
141
|
+
data.forEach { (key, value) -> put(key, value) }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Parse actions from JSON string if present
|
|
145
|
+
val actions = data["actions"]?.let { actionsStr ->
|
|
146
|
+
try {
|
|
147
|
+
parseActionsFromJson(JSONArray(actionsStr))
|
|
148
|
+
} catch (e: Exception) {
|
|
149
|
+
BridgeUtils.logError(TAG, "Failed to parse actions from FCM data", e)
|
|
150
|
+
null
|
|
151
|
+
}
|
|
152
|
+
} ?: payload.optJSONArray("actions")?.let { parseActionsFromJson(it) }
|
|
153
|
+
|
|
154
|
+
// Extract custom data only from the "data" field
|
|
155
|
+
val customData = mutableMapOf<String, Any>().apply {
|
|
156
|
+
data["data"]?.let { dataStr ->
|
|
157
|
+
try {
|
|
158
|
+
val dataJson = JSONObject(dataStr)
|
|
159
|
+
dataJson.keys().forEach { key ->
|
|
160
|
+
put(key, dataJson.get(key))
|
|
161
|
+
}
|
|
162
|
+
} catch (e: Exception) {
|
|
163
|
+
BridgeUtils.logError(TAG, "Failed to parse custom data from FCM", e)
|
|
164
|
+
// If parsing fails, treat it as a string value
|
|
165
|
+
put("data", dataStr)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Handle badge - it might come as string from FCM
|
|
171
|
+
val badge = data["badge"]?.toIntOrNull() ?: payload.optInt("badge", -1).takeIf { it >= 0 }
|
|
172
|
+
|
|
173
|
+
val config = NotificationConfig(
|
|
174
|
+
title = data["title"] ?: payload.optString("title", NotificationConstants.DEFAULT_NOTIFICATION_TITLE),
|
|
175
|
+
body = data["body"] ?: payload.optString("body", NotificationConstants.DEFAULT_NOTIFICATION_BODY),
|
|
176
|
+
channel = data["channel"] ?: payload.optString("channel", NotificationConstants.DEFAULT_CHANNEL_ID),
|
|
177
|
+
badge = badge,
|
|
178
|
+
actions = actions,
|
|
179
|
+
largeImage = (data["largeImage"] ?: payload.optString("largeImage")).takeIf { it?.isNotBlank() == true },
|
|
180
|
+
style = try {
|
|
181
|
+
NotificationStyle.valueOf(data["style"] ?: payload.optString("style", "BASIC"))
|
|
182
|
+
} catch (e: IllegalArgumentException) {
|
|
183
|
+
NotificationStyle.BASIC
|
|
184
|
+
},
|
|
185
|
+
priority = data["priority"]?.toIntOrNull() ?: payload.optInt("priority", NotificationCompat.PRIORITY_DEFAULT),
|
|
186
|
+
vibrate = data["vibrate"]?.toBooleanStrictOrNull() ?: payload.optBoolean("vibrate", true),
|
|
187
|
+
autoCancel = data["autoCancel"]?.toBooleanStrictOrNull() ?: payload.optBoolean("autoCancel", true),
|
|
188
|
+
ongoing = data["ongoing"]?.toBooleanStrictOrNull() ?: payload.optBoolean("ongoing", false),
|
|
189
|
+
data = customData
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
NotificationUtils(context).scheduleLocalNotification(context, config)
|
|
193
|
+
webView?.let { notifyWebOfReceivedPush(it, config.title, config.body, config.channel, customData) }
|
|
194
|
+
} catch (e: Exception) {
|
|
195
|
+
BridgeUtils.logError(TAG, "Error handling push notification", e)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Handle token refresh (called from broadcast receiver)
|
|
201
|
+
*/
|
|
202
|
+
fun handleTokenRefresh(webView: WebView?, newToken: String) {
|
|
203
|
+
webView?.let {
|
|
204
|
+
val tokenData = """{"token": "$newToken", "refreshed": true, "provider": "$PROVIDER_FCM"}"""
|
|
205
|
+
BridgeUtils.notifyWeb(it, BridgeUtils.WebEvents.PUSH_NOTIFICATION_TOKEN, tokenData)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Subscribe to topic
|
|
211
|
+
*/
|
|
212
|
+
fun subscribeToTopic(context: Context, topic: String): Boolean {
|
|
213
|
+
return try {
|
|
214
|
+
FirebaseMessaging.getInstance().subscribeToTopic(topic)
|
|
215
|
+
.addOnCompleteListener { task ->
|
|
216
|
+
if (task.isSuccessful) {
|
|
217
|
+
BridgeUtils.logInfo(TAG, "Subscribed to Firebase topic: $topic")
|
|
218
|
+
val topics = getSubscribedTopics(context).toMutableSet()
|
|
219
|
+
topics.add(topic)
|
|
220
|
+
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
221
|
+
.edit().putStringSet(KEY_SUBSCRIBED_TOPICS, topics).apply()
|
|
222
|
+
} else {
|
|
223
|
+
BridgeUtils.logError(TAG, "Failed to subscribe to topic: $topic", task.exception)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
BridgeUtils.logInfo(TAG, "Subscribing to topic: $topic")
|
|
227
|
+
true
|
|
228
|
+
} catch (e: Exception) {
|
|
229
|
+
BridgeUtils.logError(TAG, "Failed to subscribe to topic: $topic", e)
|
|
230
|
+
false
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Unsubscribe from topic
|
|
236
|
+
*/
|
|
237
|
+
fun unsubscribeFromTopic(context: Context, topic: String): Boolean {
|
|
238
|
+
return try {
|
|
239
|
+
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic)
|
|
240
|
+
.addOnCompleteListener { task ->
|
|
241
|
+
if (task.isSuccessful) {
|
|
242
|
+
BridgeUtils.logInfo(TAG, "Unsubscribed from Firebase topic: $topic")
|
|
243
|
+
val topics = getSubscribedTopics(context).toMutableSet()
|
|
244
|
+
topics.remove(topic)
|
|
245
|
+
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
246
|
+
.edit().putStringSet(KEY_SUBSCRIBED_TOPICS, topics).apply()
|
|
247
|
+
} else {
|
|
248
|
+
BridgeUtils.logError(TAG, "Failed to unsubscribe from topic: $topic", task.exception)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
BridgeUtils.logInfo(TAG, "Unsubscribing from topic: $topic")
|
|
252
|
+
true
|
|
253
|
+
} catch (e: Exception) {
|
|
254
|
+
BridgeUtils.logError(TAG, "Failed to unsubscribe from topic: $topic", e)
|
|
255
|
+
false
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Get current push token
|
|
261
|
+
*/
|
|
262
|
+
fun getPushToken(context: Context): String? {
|
|
263
|
+
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
264
|
+
.getString(KEY_PUSH_TOKEN, null)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Get subscribed topics
|
|
269
|
+
*/
|
|
270
|
+
fun getSubscribedTopics(context: Context): Set<String> {
|
|
271
|
+
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
272
|
+
.getStringSet(KEY_SUBSCRIBED_TOPICS, emptySet()) ?: emptySet()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Delete all push data
|
|
277
|
+
*/
|
|
278
|
+
fun deleteAllPushData(context: Context): Boolean {
|
|
279
|
+
return try {
|
|
280
|
+
FirebaseMessaging.getInstance().deleteToken()
|
|
281
|
+
.addOnCompleteListener { task ->
|
|
282
|
+
if (task.isSuccessful) {
|
|
283
|
+
BridgeUtils.logInfo(TAG, "Firebase token deleted")
|
|
284
|
+
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().clear().apply()
|
|
285
|
+
BridgeUtils.logInfo(TAG, "All push data deleted")
|
|
286
|
+
} else {
|
|
287
|
+
BridgeUtils.logError(TAG, "Failed to delete Firebase token", task.exception)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
true
|
|
291
|
+
} catch (e: Exception) {
|
|
292
|
+
BridgeUtils.logError(TAG, "Failed to delete push data", e)
|
|
293
|
+
false
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Get current push provider
|
|
299
|
+
*/
|
|
300
|
+
fun getPushProvider(@Suppress("UNUSED_PARAMETER") context: Context): String {
|
|
301
|
+
return PROVIDER_FCM
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Check if FCM is available
|
|
306
|
+
*/
|
|
307
|
+
fun isAvailable(context: Context): Boolean {
|
|
308
|
+
return try {
|
|
309
|
+
val googleApiAvailability = GoogleApiAvailability.getInstance()
|
|
310
|
+
val resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context)
|
|
311
|
+
resultCode == ConnectionResult.SUCCESS
|
|
312
|
+
} catch (e: Exception) {
|
|
313
|
+
BridgeUtils.logError(TAG, "Error checking FCM availability", e)
|
|
314
|
+
false
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ==================== PRIVATE HELPERS ====================
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Parse actions from JSONArray (for unified format)
|
|
322
|
+
*/
|
|
323
|
+
private fun parseActionsFromJson(actionsArray: JSONArray?): List<NotificationAction>? {
|
|
324
|
+
if (actionsArray == null || actionsArray.length() == 0) return null
|
|
325
|
+
|
|
326
|
+
return try {
|
|
327
|
+
val actions = mutableListOf<NotificationAction>()
|
|
328
|
+
for (i in 0 until actionsArray.length()) {
|
|
329
|
+
val actionObj = actionsArray.getJSONObject(i)
|
|
330
|
+
val action = NotificationAction(
|
|
331
|
+
title = actionObj.optString("title", "Action ${i + 1}"),
|
|
332
|
+
actionId = actionObj.optString("action", actionObj.optString("id", "action_$i"))
|
|
333
|
+
)
|
|
334
|
+
actions.add(action)
|
|
335
|
+
}
|
|
336
|
+
actions
|
|
337
|
+
} catch (e: Exception) {
|
|
338
|
+
BridgeUtils.logError(TAG, "Failed to parse actions from JSONArray", e)
|
|
339
|
+
null
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private fun storePushToken(context: Context, token: String) {
|
|
344
|
+
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
345
|
+
.edit()
|
|
346
|
+
.putString(KEY_PUSH_TOKEN, token)
|
|
347
|
+
.apply()
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private fun notifyWebOfReceivedPush(webView: WebView, title: String, body: String, channel: String, customData: Map<String, Any>) {
|
|
351
|
+
try {
|
|
352
|
+
val messageData = JSONObject().apply {
|
|
353
|
+
put("provider", PROVIDER_FCM)
|
|
354
|
+
put("timestamp", System.currentTimeMillis())
|
|
355
|
+
put("type", "push_notification")
|
|
356
|
+
put("data", JSONObject(customData))
|
|
357
|
+
put("notification", JSONObject().apply {
|
|
358
|
+
put("title", title)
|
|
359
|
+
put("body", body)
|
|
360
|
+
put("channel", channel)
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
BridgeUtils.notifyWeb(webView, BridgeUtils.WebEvents.NOTIFICATION_RECEIVED, messageData.toString())
|
|
364
|
+
} catch (e: Exception) {
|
|
365
|
+
BridgeUtils.logError(TAG, "Failed to notify web", e)
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Send broadcast when a message is received
|
|
371
|
+
*/
|
|
372
|
+
private fun sendMessageReceivedBroadcast(context: Context, data: Map<String, String>) {
|
|
373
|
+
val intent = Intent(ACTION_MESSAGE_RECEIVED).apply {
|
|
374
|
+
putExtra(EXTRA_MESSAGE_DATA, HashMap(data))
|
|
375
|
+
}
|
|
376
|
+
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
|
377
|
+
BridgeUtils.logInfo(TAG, "Broadcast sent: $ACTION_MESSAGE_RECEIVED")
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Send broadcast when token is refreshed
|
|
382
|
+
*/
|
|
383
|
+
private fun sendTokenRefreshedBroadcast(context: Context, token: String) {
|
|
384
|
+
val intent = Intent(ACTION_TOKEN_REFRESHED).apply {
|
|
385
|
+
putExtra(EXTRA_TOKEN, token)
|
|
386
|
+
}
|
|
387
|
+
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
|
388
|
+
BridgeUtils.logInfo(TAG, "Broadcast sent: $ACTION_TOKEN_REFRESHED")
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Note: Firebase push notification service would be defined here when Firebase is available.
|
|
395
|
+
* Since Firebase is conditionally loaded, the actual service implementation should be
|
|
396
|
+
* in a separate file that's only compiled when Firebase dependencies are present.
|
|
397
|
+
*
|
|
398
|
+
* For now, this class provides local notification functionality only.
|
|
399
|
+
*/
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
|
2
|
+
buildscript {
|
|
3
|
+
dependencies {
|
|
4
|
+
classpath("com.google.gms:google-services:4.4.0")
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
plugins {
|
|
3
9
|
alias(libs.plugins.android.application) apply false
|
|
4
10
|
alias(libs.plugins.jetbrains.kotlin.android) apply false
|
|
@@ -8,7 +8,10 @@ espressoCore = "3.6.1"
|
|
|
8
8
|
appcompat = "1.7.0"
|
|
9
9
|
material = "1.12.0"
|
|
10
10
|
constraintlayout = "2.1.4"
|
|
11
|
-
webkit = "1.
|
|
11
|
+
webkit = "1.13.0"
|
|
12
|
+
googleServices = "4.4.0"
|
|
13
|
+
androidxCredentials = "1.3.0"
|
|
14
|
+
googleId = "1.1.1"
|
|
12
15
|
|
|
13
16
|
[libraries]
|
|
14
17
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
|
@@ -19,8 +22,11 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
|
|
|
19
22
|
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
|
20
23
|
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
|
|
21
24
|
androidx-webkit = { group = "androidx.webkit", name = "webkit", version.ref = "webkit" }
|
|
25
|
+
androidx-credentials = { group = "androidx.credentials", name = "credentials", version.ref = "androidxCredentials" }
|
|
26
|
+
androidx-credentials-play-services-auth = { group = "androidx.credentials", name = "credentials-play-services-auth", version.ref = "androidxCredentials" }
|
|
27
|
+
googleid = { group = "com.google.android.libraries.identity.googleid", name = "googleid", version.ref = "googleId" }
|
|
22
28
|
|
|
23
29
|
[plugins]
|
|
24
30
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
|
25
31
|
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
|
26
|
-
|
|
32
|
+
google-services = { id = "com.google.gms.google-services", version.ref = "googleServices" }
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
"use strict";var _fs=_interopRequireDefault(require("fs"));var _child_process=require("child_process");var _utils=require("./utils.js");var _TerminalProgress=_interopRequireDefault(require("./TerminalProgress.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}const
|
|
2
|
-
try{await(0,_utils.runCommand)(
|
|
1
|
+
"use strict";var _fs=_interopRequireDefault(require("fs"));var _path=_interopRequireDefault(require("path"));var _child_process=require("child_process");var _utils=require("./utils.js");var _TerminalProgress=_interopRequireDefault(require("./TerminalProgress.js"));var _setupServer=require("./setupServer.js");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}const catalystCorePath=_path.default.dirname(require.resolve("catalyst-core/package.json"));const pwd=_path.default.join(catalystCorePath,"dist/native");const configPath=`${process.env.PWD}/config/config.json`;const steps={java:"Check Java Environment",config:"Initialize Configuration",androidTools:"Validate Android Tools",emulator:"Configure Android Emulator",properties:"Update Local Properties",saveConfig:"Save Configuration",setupServer:"Setup Server"};const progressPaddingConfig={titlePaddingTop:2,titlePaddingBottom:1,stepPaddingLeft:4,stepSpacing:1,errorPaddingLeft:6,bottomMargin:2};const progress=new _TerminalProgress.default(steps,"Catalyst Universal Android Setup",progressPaddingConfig);async function checkJavaInstallation(){try{(0,_utils.runCommand)("java -version");(0,_utils.runCommand)("javac -version");progress.log("Java is installed and configured","success");return true;}catch(error){progress.log("Java installation not found or not properly configured","error");return false;}}async function installJava(){progress.log("Installing Java (Zulu JDK 17)...");try{try{(0,_utils.runCommand)("brew --version");}catch(error){throw new Error("Homebrew is required but not installed. Please install Homebrew first.");}const javaHome="/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home";// Try installing Java
|
|
2
|
+
try{await(0,_utils.runCommand)("brew install --cask zulu@17");}catch(error){if(error.message.includes("already installed")){progress.log("Attempting to reinstall Java...","info");try{await(0,_utils.runCommand)("brew reinstall --cask zulu@17");}catch(reinstallError){throw new Error(`Failed to reinstall Java: ${reinstallError.message}. Please run 'brew reinstall --cask zulu@17' manually.`);}}else{throw error;}}// Verify Java installation
|
|
3
3
|
if(!_fs.default.existsSync(javaHome)){throw new Error(`Java installation not found at ${javaHome}. Please verify the installation manually.`);}// Set up environment variables
|
|
4
4
|
const homeDir=process.env.HOME;const shellProfile=`${homeDir}/.zshrc`;const exportCommand=`\n# Java Configuration\nexport JAVA_HOME=${javaHome}\nexport PATH=$JAVA_HOME/bin:$PATH\n`;try{_fs.default.appendFileSync(shellProfile,exportCommand);}catch(error){throw new Error(`Failed to update ${shellProfile}: ${error.message}. Please add the following lines manually:\n${exportCommand}`);}// Set for current process
|
|
5
5
|
process.env.JAVA_HOME=javaHome;process.env.PATH=`${javaHome}/bin:${process.env.PATH}`;// Verify Java configuration
|
|
6
|
-
try{const javaVersion=(0,_utils.runCommand)(
|
|
6
|
+
try{const javaVersion=(0,_utils.runCommand)("java -version");progress.log("Java installed and configured successfully","success");progress.log(`Java Version: ${javaVersion}`,"info");progress.log(`IMPORTANT: Please run the following commands to complete setup:`,"warning");progress.log(`1. source ${shellProfile}`,"info");progress.log(`2. echo $JAVA_HOME`,"info");return true;}catch(error){throw new Error(`Java installation verified but environment not configured. Please run:\n1. source ${shellProfile}\n2. echo $JAVA_HOME`);}}catch(error){progress.log(error.message,"error");progress.log("Manual Setup Instructions:","info");progress.log("1. Run: brew reinstall --cask zulu@17","info");progress.log("2. Add to ~/.zshrc:","info");progress.log(" export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home","info");progress.log(" export PATH=$JAVA_HOME/bin:$PATH","info");progress.log("3. Run: source ~/.zshrc","info");throw error;}}async function validateJavaEnvironment(){progress.start("java");const hasJava=await checkJavaInstallation();if(!hasJava){progress.log("Java installation required. Starting installation process...");const javaInstalled=await installJava();if(!javaInstalled){progress.fail("java","Failed to set up Java environment");throw new Error("Failed to set up Java environment");}}progress.complete("java");}async function initializeConfig(){const configFile=_fs.default.readFileSync(configPath,"utf8");const config=JSON.parse(configFile);const{WEBVIEW_CONFIG}=config;if(!WEBVIEW_CONFIG||Object.keys(WEBVIEW_CONFIG).length===0){progress.log("WebView Config missing in "+configPath,"error");process.exit(1);}if(!WEBVIEW_CONFIG.android){WEBVIEW_CONFIG.android={};}return{WEBVIEW_CONFIG};}async function saveConfig(newConfig){try{const existingConfigFile=_fs.default.readFileSync(configPath,"utf8");const existingConfig=JSON.parse(existingConfigFile);const updatedConfig={...existingConfig,WEBVIEW_CONFIG:{...existingConfig.WEBVIEW_CONFIG,android:newConfig.WEBVIEW_CONFIG.android}};_fs.default.writeFileSync(configPath,JSON.stringify(updatedConfig,null,2));progress.log("Configuration saved successfully","success");}catch(error){progress.log("Failed to save configuration: "+error.message,"error");process.exit(1);}}function validateAndroidTools(androidConfig){const ANDROID_SDK=androidConfig.sdkPath;const EMULATOR_PATH=`${ANDROID_SDK}/emulator/emulator`;const ADB_PATH=`${ANDROID_SDK}/platform-tools/adb`;if(!ANDROID_SDK){throw new Error("Android SDK path is not configured");}if(!_fs.default.existsSync(ANDROID_SDK)){throw new Error(`Android SDK path does not exist: ${ANDROID_SDK}`);}if(!_fs.default.existsSync(ADB_PATH)){throw new Error(`ADB not found at: ${ADB_PATH}`);}try{(0,_utils.runCommand)(`${ADB_PATH} version`);progress.log("ADB is valid","success");}catch(error){throw new Error(`ADB is not working properly: ${error.message}`);}if(!_fs.default.existsSync(EMULATOR_PATH)){throw new Error(`Emulator not found at: ${EMULATOR_PATH}`);}try{(0,_utils.runCommand)(`${EMULATOR_PATH} -version`);progress.log("Emulator is valid","success");}catch(error){throw new Error(`Emulator is not working properly: ${error.message}`);}try{const avdOutput=(0,_utils.runCommand)(`${EMULATOR_PATH} -list-avds`);if(!avdOutput.includes(androidConfig.emulatorName)){throw new Error(`Specified emulator "${androidConfig.emulatorName}" not found in available AVDs`);}progress.log(`Emulator "${androidConfig.emulatorName}" exists`,"success");}catch(error){throw new Error(`Error checking emulator AVD: ${error.message}`);}progress.log("Android tools validation completed successfully!","success");return{EMULATOR_PATH,ADB_PATH};}async function checkEmulator(ADB_PATH){try{const devices=(0,_utils.runCommand)(`${ADB_PATH} devices`);return devices.includes("emulator");}catch(error){progress.log(`Error checking emulator: ${error}`,"error");return false;}}async function startEmulator(EMULATOR_PATH,androidConfig){progress.log(`Starting emulator: ${androidConfig.emulatorName}...`);// eslint-disable-next-line security/detect-child-process
|
|
7
|
+
(0,_child_process.exec)(`${EMULATOR_PATH} -avd ${androidConfig.emulatorName} -read-only > /dev/null &`,error=>{if(error){progress.log(`Error starting emulator: ${error}`,"error");}});}async function updateLocalProperties(sdkPath){progress.start("properties");try{(0,_utils.runCommand)(`cd ${pwd}/androidProject && ./gradlew updateSdkPath -PsdkPath="${sdkPath}"`);progress.log("Updated local.properties successfully","success");progress.complete("properties");}catch(error){progress.fail("properties",`Failed to update local.properties: ${error.message}`);throw error;}}async function setupAndroidEnvironment(){try{await validateJavaEnvironment();progress.start("config");await initializeConfig();const config=await(0,_utils.validateAndCompleteConfig)("android",configPath);progress.complete("config");progress.start("androidTools");const{EMULATOR_PATH,ADB_PATH}=validateAndroidTools(config.android);progress.complete("androidTools");progress.start("emulator");const emulatorRunning=await checkEmulator(ADB_PATH);if(!emulatorRunning){progress.log("No emulator running, attempting to start one...");await startEmulator(EMULATOR_PATH,config.android);}else{progress.log("Emulator already running, proceeding with installation...","success");}progress.complete("emulator");if(config.android?.sdkPath){await updateLocalProperties(config.android.sdkPath);}progress.start("saveConfig");await saveConfig({WEBVIEW_CONFIG:config});progress.complete("saveConfig");progress.start("setupServer");await(0,_setupServer.setupServer)(configPath);progress.complete("setupServer");progress.printTreeContent("Configuration Explanation",["WEBVIEW_CONFIG: Main configuration object for the WebView setup",{text:"port: Port number for the WebView server",indent:1,prefix:"├─ ",color:"gray"},{text:"android: Android-specific configuration",indent:1,prefix:"└─ ",color:"gray"},{text:"buildType: Build type (debug/release)",indent:2,prefix:"├─ ",color:"gray"},{text:"sdkPath: Android SDK path",indent:2,prefix:"├─ ",color:"gray"},{text:"emulatorName: Selected Android emulator name",indent:2,prefix:"└─ ",color:"gray"}]);progress.printTreeContent("Final Configuration",[JSON.stringify(config,null,2)]);process.exit(0);}catch(error){if(progress.currentStep){progress.fail(progress.currentStep.id,error.message);}process.exit(1);}}// Execute the main setup
|
|
7
8
|
setupAndroidEnvironment();
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _NativeInterfaces=require("./constants/NativeInterfaces.js");var _NativeBridge=_interopRequireDefault(require("./utils/NativeBridge.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}class WebBridge{constructor(){this.handlers=new Map();this.initialized=false;this._logInitialization();}/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _NativeInterfaces=require("./constants/NativeInterfaces.js");var _NativeBridge=_interopRequireDefault(require("./utils/NativeBridge.js"));var _CameraUtils=_interopRequireDefault(require("./utils/CameraUtils.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}class WebBridge{constructor(){this.handlers=new Map();this.initialized=false;this._logInitialization();}/**
|
|
2
2
|
* Log initialization info
|
|
3
3
|
*/_logInitialization(){console.log("🌉 WebBridge initialized");console.log("🌉 Available callback interfaces:",_NativeInterfaces.ALL_CALLBACKS.length);if(process.env.NODE_ENV==="development"){(0,_NativeInterfaces.debugInterfaces)();}}/**
|
|
4
4
|
* Static method to initialize WebBridge on window object
|
|
@@ -40,7 +40,20 @@ if(this.handlers.has(interfaceName)){console.warn(`🌉 Interface ${interfaceNam
|
|
|
40
40
|
* @param {string} interfaceName - The callback interface to test
|
|
41
41
|
* @param {any} testData - Test data to pass
|
|
42
42
|
*/testCallback=(interfaceName,testData="test")=>{if(process.env.NODE_ENV!=="development"){console.warn("🌉 testCallback is only available in development mode");return;}console.log(`🌉 Testing callback: ${interfaceName}`);this.callback(interfaceName,testData);};/**
|
|
43
|
+
* Request haptic feedback
|
|
44
|
+
* @param {string} feedbackType - Type of haptic feedback (VIRTUAL_KEY, LONG_PRESS, DEFAULT)
|
|
45
|
+
* @returns {Promise<Object>} - Promise that resolves with haptic feedback result or rejects with error
|
|
46
|
+
*/requestHapticFeedback=(feedbackType="VIRTUAL_KEY")=>{return new Promise((resolve,reject)=>{const cleanup=()=>{this.unregister(_NativeInterfaces.NATIVE_CALLBACKS.HAPTIC_FEEDBACK);};this.register(_NativeInterfaces.NATIVE_CALLBACKS.HAPTIC_FEEDBACK,data=>{cleanup();try{const result=typeof data==="string"?JSON.parse(data):data;if(result.error){reject(new Error(result.error));}else{resolve(result);}}catch(error){reject(error);}});try{_NativeBridge.default.haptic.feedback(feedbackType);}catch(error){cleanup();reject(error);}});};/**
|
|
47
|
+
* Open camera and capture image
|
|
48
|
+
* @param {Object} options - Camera options (quality, format, cameraDevice, flashMode, allowEditing)
|
|
49
|
+
* @returns {Promise<Object>} - Promise that resolves with camera result or rejects with error
|
|
50
|
+
*/openCamera=(options={})=>{return _CameraUtils.default.openCamera(options,this.register,this.unregister);};/**
|
|
51
|
+
* Request camera permission
|
|
52
|
+
* @param {Object} config - Permission configuration (includeDetails)
|
|
53
|
+
* @returns {Promise<Object>} - Promise that resolves with permission status or rejects with error
|
|
54
|
+
*/requestCameraPermission=(config={})=>{return _CameraUtils.default.requestCameraPermission(config,this.register,this.unregister);};/**
|
|
43
55
|
* Get device information
|
|
44
56
|
* @returns {Promise<Object>} - Promise that resolves with device info or rejects with error
|
|
45
|
-
*/getDeviceInfo=()=>{
|
|
46
|
-
const
|
|
57
|
+
*/getDeviceInfo=()=>{const{platform,isNativeEnvironment}=_NativeBridge.default.getEnvironmentInfo();// Handle web environment
|
|
58
|
+
if(!isNativeEnvironment||platform==="web"){return new Promise(resolve=>{const webDeviceInfo={model:navigator.userAgent,manufacturer:"browser",platform:"web",screenWidth:screen.width,screenHeight:screen.height,screenDensity:window.devicePixelRatio};resolve(webDeviceInfo);});}// Key mapping from native to web keys
|
|
59
|
+
const DEVICE_INFO_KEY_MAP={android:{model:"model",manufacturer:"manufacturer",platform:"platform",screenWidth:"screenWidth",screenHeight:"screenHeight",screenDensity:"screenDensity",appInfo:"appInfo"},ios:{model:"model",manufacturer:"manufacturer",platform:"platform",screenWidth:"screenWidth",screenHeight:"screenHeight",screenDensity:"screenDensity",appInfo:"appInfo"}};const parseDeviceInfo=data=>{const rawDeviceInfo=typeof data==="string"?JSON.parse(data):data;const platformMapping=DEVICE_INFO_KEY_MAP[platform]||{};return Object.fromEntries(Object.entries(rawDeviceInfo).map(([key,value])=>[platformMapping[key]||key,value]));};return new Promise((resolve,reject)=>{const cleanup=()=>{this.unregister(_NativeInterfaces.NATIVE_CALLBACKS.ON_DEVICE_INFO_SUCCESS);this.unregister(_NativeInterfaces.NATIVE_CALLBACKS.ON_DEVICE_INFO_ERROR);};this.register(_NativeInterfaces.NATIVE_CALLBACKS.ON_DEVICE_INFO_SUCCESS,data=>{cleanup();resolve(parseDeviceInfo(data));});this.register(_NativeInterfaces.NATIVE_CALLBACKS.ON_DEVICE_INFO_ERROR,error=>{cleanup();reject(new Error(error));});try{_NativeBridge.default.device.getDeviceInfo();}catch(error){cleanup();reject(error);}});};}var _default=exports.default=WebBridge;
|
|
@@ -1,24 +1,42 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isValidInterface=exports.isValidCommand=exports.isValidCallback=exports.getInterfacesByCategory=exports.default=exports.debugInterfaces=exports.RESPONSE_STATUS=exports.PERMISSION_STATUS=exports.NATIVE_COMMANDS=exports.NATIVE_CALLBACKS=exports.INTERFACE_CATEGORIES=exports.INTENT_STATES=exports.HAPTIC_FEEDBACK_TYPES=exports.FILE_PICKER_STATES=exports.ALL_INTERFACES=exports.ALL_COMMANDS=exports.ALL_CALLBACKS=void 0;// Native Bridge Interface Constants
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isValidInterface=exports.isValidCommand=exports.isValidCallback=exports.getInterfacesByCategory=exports.default=exports.debugInterfaces=exports.TRANSPORT_TYPES=exports.RESPONSE_STATUS=exports.PERMISSION_STATUS=exports.NATIVE_COMMANDS=exports.NATIVE_CALLBACKS=exports.INTERFACE_CATEGORIES=exports.INTENT_STATES=exports.HAPTIC_FEEDBACK_TYPES=exports.FILE_PICKER_STATES=exports.CAMERA_SOURCE=exports.CAMERA_QUALITY=exports.CAMERA_FORMAT=exports.CAMERA_FLASH_MODE=exports.CAMERA_DEVICE=exports.ALL_INTERFACES=exports.ALL_COMMANDS=exports.ALL_CALLBACKS=void 0;// Native Bridge Interface Constants
|
|
2
2
|
// Centralized definitions for all native interface communications
|
|
3
3
|
// Command Interfaces: Web → Native (outgoing commands)
|
|
4
4
|
const NATIVE_COMMANDS=exports.NATIVE_COMMANDS={// Camera commands
|
|
5
5
|
OPEN_CAMERA:"openCamera",REQUEST_CAMERA_PERMISSION:"requestCameraPermission",// File commands
|
|
6
6
|
PICK_FILE:"pickFile",OPEN_FILE_WITH_INTENT:"openFileWithIntent",// Haptic feedback commands
|
|
7
|
-
REQUEST_HAPTIC_FEEDBACK:"requestHapticFeedback",//
|
|
8
|
-
|
|
7
|
+
REQUEST_HAPTIC_FEEDBACK:"requestHapticFeedback",// Notification commands
|
|
8
|
+
SCHEDULE_LOCAL_NOTIFICATION:"scheduleLocalNotification",CANCEL_LOCAL_NOTIFICATION:"cancelLocalNotification",REQUEST_NOTIFICATION_PERMISSION:"requestNotificationPermission",REGISTER_FOR_PUSH_NOTIFICATIONS:"registerForPushNotifications",UPDATE_BADGE_COUNT:"updateBadgeCount",SUBSCRIBE_TO_TOPIC:"subscribeToTopic",UNSUBSCRIBE_FROM_TOPIC:"unsubscribeFromTopic",GET_SUBSCRIBED_TOPICS:"getSubscribedTopics",// Device info commands
|
|
9
|
+
GET_DEVICE_INFO:"getDeviceInfo",// Network commands
|
|
10
|
+
GET_NETWORK_STATUS:"getNetworkStatus",// Auth commands
|
|
11
|
+
GOOGLE_SIGN_IN:"googleSignIn",// Safe area commands
|
|
12
|
+
GET_SAFE_AREA:"getSafeArea",// Security commands
|
|
13
|
+
SET_SCREEN_SECURE:"setScreenSecure",GET_SCREEN_SECURE:"getScreenSecure",CLEAR_WEB_DATA:"clearWebData"};// Callback Interfaces: Native → Web (incoming events/callbacks)
|
|
9
14
|
const NATIVE_CALLBACKS=exports.NATIVE_CALLBACKS={// Camera callbacks
|
|
10
15
|
CAMERA_PERMISSION_STATUS:"CAMERA_PERMISSION_STATUS",ON_CAMERA_CAPTURE:"ON_CAMERA_CAPTURE",ON_CAMERA_ERROR:"ON_CAMERA_ERROR",// File picker callbacks
|
|
11
16
|
ON_FILE_PICKED:"ON_FILE_PICKED",ON_FILE_PICK_ERROR:"ON_FILE_PICK_ERROR",ON_FILE_PICK_CANCELLED:"ON_FILE_PICK_CANCELLED",ON_FILE_PICK_STATE_UPDATE:"ON_FILE_PICK_STATE_UPDATE",// Intent callbacks
|
|
12
17
|
ON_INTENT_SUCCESS:"ON_INTENT_SUCCESS",ON_INTENT_ERROR:"ON_INTENT_ERROR",ON_INTENT_CANCELLED:"ON_INTENT_CANCELLED",// Haptic feedback callbacks
|
|
13
|
-
HAPTIC_FEEDBACK:"HAPTIC_FEEDBACK",//
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
HAPTIC_FEEDBACK:"HAPTIC_FEEDBACK",// Notification callbacks
|
|
19
|
+
NOTIFICATION_PERMISSION_STATUS:"NOTIFICATION_PERMISSION_STATUS",LOCAL_NOTIFICATION_SCHEDULED:"LOCAL_NOTIFICATION_SCHEDULED",LOCAL_NOTIFICATION_CANCELLED:"LOCAL_NOTIFICATION_CANCELLED",PUSH_NOTIFICATION_TOKEN:"PUSH_NOTIFICATION_TOKEN",NOTIFICATION_RECEIVED:"NOTIFICATION_RECEIVED",NOTIFICATION_ACTION_PERFORMED:"NOTIFICATION_ACTION_PERFORMED",NOTIFICATION_TAPPED:"NOTIFICATION_TAPPED",TOPIC_SUBSCRIPTION_RESULT:"TOPIC_SUBSCRIPTION_RESULT",SUBSCRIBED_TOPICS_RESULT:"SUBSCRIBED_TOPICS_RESULT",// Device info callbacks
|
|
20
|
+
ON_DEVICE_INFO_SUCCESS:"ON_DEVICE_INFO_SUCCESS",ON_DEVICE_INFO_ERROR:"ON_DEVICE_INFO_ERROR",// Auth callbacks
|
|
21
|
+
ON_GOOGLE_SIGN_IN_SUCCESS:"ON_GOOGLE_SIGN_IN_SUCCESS",ON_GOOGLE_SIGN_IN_ERROR:"ON_GOOGLE_SIGN_IN_ERROR",ON_GOOGLE_SIGN_IN_CANCELLED:"ON_GOOGLE_SIGN_IN_CANCELLED",// Network callbacks
|
|
22
|
+
NETWORK_STATUS_CHANGED:"NETWORK_STATUS_CHANGED",// Safe area callbacks
|
|
23
|
+
ON_SAFE_AREA_INSETS_UPDATED:"ON_SAFE_AREA_INSETS_UPDATED",// Security callbacks
|
|
24
|
+
ON_SCREEN_SECURE_SET:"ON_SCREEN_SECURE_SET",ON_SCREEN_SECURE_STATUS:"ON_SCREEN_SECURE_STATUS",ON_SCREEN_SECURE_ERROR:"ON_SCREEN_SECURE_ERROR",ON_WEB_DATA_CLEARED:"ON_WEB_DATA_CLEARED",ON_WEB_DATA_CLEAR_ERROR:"ON_WEB_DATA_CLEAR_ERROR"};// Interface Categories for easier management
|
|
25
|
+
const INTERFACE_CATEGORIES=exports.INTERFACE_CATEGORIES={CAMERA:{commands:[NATIVE_COMMANDS.OPEN_CAMERA,NATIVE_COMMANDS.REQUEST_CAMERA_PERMISSION],callbacks:[NATIVE_CALLBACKS.CAMERA_PERMISSION_STATUS,NATIVE_CALLBACKS.ON_CAMERA_CAPTURE,NATIVE_CALLBACKS.ON_CAMERA_ERROR]},FILE:{commands:[NATIVE_COMMANDS.PICK_FILE,NATIVE_COMMANDS.OPEN_FILE_WITH_INTENT],callbacks:[NATIVE_CALLBACKS.ON_FILE_PICKED,NATIVE_CALLBACKS.ON_FILE_PICK_ERROR,NATIVE_CALLBACKS.ON_FILE_PICK_CANCELLED,NATIVE_CALLBACKS.ON_FILE_PICK_STATE_UPDATE]},INTENT:{commands:[NATIVE_COMMANDS.OPEN_FILE_WITH_INTENT],callbacks:[NATIVE_CALLBACKS.ON_INTENT_SUCCESS,NATIVE_CALLBACKS.ON_INTENT_ERROR,NATIVE_CALLBACKS.ON_INTENT_CANCELLED]},HAPTIC:{commands:[NATIVE_COMMANDS.REQUEST_HAPTIC_FEEDBACK],callbacks:[NATIVE_CALLBACKS.HAPTIC_FEEDBACK]},NOTIFICATION:{commands:[NATIVE_COMMANDS.SCHEDULE_LOCAL_NOTIFICATION,NATIVE_COMMANDS.CANCEL_LOCAL_NOTIFICATION,NATIVE_COMMANDS.REQUEST_NOTIFICATION_PERMISSION,NATIVE_COMMANDS.REGISTER_FOR_PUSH_NOTIFICATIONS,NATIVE_COMMANDS.UPDATE_BADGE_COUNT,NATIVE_COMMANDS.SUBSCRIBE_TO_TOPIC,NATIVE_COMMANDS.UNSUBSCRIBE_FROM_TOPIC,NATIVE_COMMANDS.GET_SUBSCRIBED_TOPICS],callbacks:[NATIVE_CALLBACKS.NOTIFICATION_PERMISSION_STATUS,NATIVE_CALLBACKS.LOCAL_NOTIFICATION_SCHEDULED,NATIVE_CALLBACKS.LOCAL_NOTIFICATION_CANCELLED,NATIVE_CALLBACKS.PUSH_NOTIFICATION_TOKEN,NATIVE_CALLBACKS.NOTIFICATION_RECEIVED,NATIVE_CALLBACKS.NOTIFICATION_ACTION_PERFORMED,NATIVE_CALLBACKS.NOTIFICATION_TAPPED,NATIVE_CALLBACKS.TOPIC_SUBSCRIPTION_RESULT,NATIVE_CALLBACKS.SUBSCRIBED_TOPICS_RESULT]},DEVICE_INFO:{commands:[NATIVE_COMMANDS.GET_DEVICE_INFO],callbacks:[NATIVE_CALLBACKS.ON_DEVICE_INFO_SUCCESS,NATIVE_CALLBACKS.ON_DEVICE_INFO_ERROR]},AUTH:{commands:[NATIVE_COMMANDS.GOOGLE_SIGN_IN],callbacks:[NATIVE_CALLBACKS.ON_GOOGLE_SIGN_IN_SUCCESS,NATIVE_CALLBACKS.ON_GOOGLE_SIGN_IN_ERROR,NATIVE_CALLBACKS.ON_GOOGLE_SIGN_IN_CANCELLED]},NETWORK:{commands:[NATIVE_COMMANDS.GET_NETWORK_STATUS],callbacks:[NATIVE_CALLBACKS.NETWORK_STATUS_CHANGED]},SECURITY:{commands:[NATIVE_COMMANDS.SET_SCREEN_SECURE,NATIVE_COMMANDS.GET_SCREEN_SECURE,NATIVE_COMMANDS.CLEAR_WEB_DATA],callbacks:[NATIVE_CALLBACKS.ON_SCREEN_SECURE_SET,NATIVE_CALLBACKS.ON_SCREEN_SECURE_ERROR,NATIVE_CALLBACKS.ON_WEB_DATA_CLEARED,NATIVE_CALLBACKS.ON_WEB_DATA_CLEAR_ERROR]}};// All available interfaces (for validation)
|
|
16
26
|
const ALL_COMMANDS=exports.ALL_COMMANDS=Object.values(NATIVE_COMMANDS);const ALL_CALLBACKS=exports.ALL_CALLBACKS=Object.values(NATIVE_CALLBACKS);const ALL_INTERFACES=exports.ALL_INTERFACES=[...ALL_COMMANDS,...ALL_CALLBACKS];// Permission status constants
|
|
17
|
-
const PERMISSION_STATUS=exports.PERMISSION_STATUS={GRANTED:"GRANTED",DENIED:"DENIED",NOT_DETERMINED:"NOT_DETERMINED",RESTRICTED:"RESTRICTED"};// Haptic feedback types
|
|
18
|
-
const HAPTIC_FEEDBACK_TYPES=exports.HAPTIC_FEEDBACK_TYPES={
|
|
27
|
+
const PERMISSION_STATUS=exports.PERMISSION_STATUS={GRANTED:"GRANTED",DENIED:"DENIED",NOT_DETERMINED:"NOT_DETERMINED",RESTRICTED:"RESTRICTED"};// Haptic feedback types (matching Android implementation)
|
|
28
|
+
const HAPTIC_FEEDBACK_TYPES=exports.HAPTIC_FEEDBACK_TYPES={VIRTUAL_KEY:"VIRTUAL_KEY",LONG_PRESS:"LONG_PRESS",DEFAULT:"DEFAULT",// Legacy types for backward compatibility
|
|
29
|
+
LIGHT:"VIRTUAL_KEY",MEDIUM:"DEFAULT",HEAVY:"LONG_PRESS"};// File picker state constants
|
|
19
30
|
const FILE_PICKER_STATES=exports.FILE_PICKER_STATES={OPENING:"opening",PROCESSING:"processing",IDLE:null};// Intent processing states
|
|
20
|
-
const INTENT_STATES=exports.INTENT_STATES={PROCESSING:"processing",DOWNLOADING:"downloading",OPENING:"opening",IDLE:null};//
|
|
31
|
+
const INTENT_STATES=exports.INTENT_STATES={PROCESSING:"processing",DOWNLOADING:"downloading",OPENING:"opening",IDLE:null};// Camera quality constants
|
|
32
|
+
const CAMERA_QUALITY=exports.CAMERA_QUALITY={HIGH:"high",MEDIUM:"medium",LOW:"low"};// Camera format constants
|
|
33
|
+
const CAMERA_FORMAT=exports.CAMERA_FORMAT={JPEG:"jpeg",PNG:"png"};// Camera device constants
|
|
34
|
+
const CAMERA_DEVICE=exports.CAMERA_DEVICE={FRONT:"front",REAR:"rear",BACK:"rear"// Alias for rear
|
|
35
|
+
};// Camera flash mode constants
|
|
36
|
+
const CAMERA_FLASH_MODE=exports.CAMERA_FLASH_MODE={AUTO:"auto",ON:"on",OFF:"off"};// Transport type constants (matching native implementation)
|
|
37
|
+
const TRANSPORT_TYPES=exports.TRANSPORT_TYPES={BASE64:"BASE64",FILE_URL:"FILE_URL",FRAMEWORK_SERVER:"FRAMEWORK_SERVER"};// Camera source constants
|
|
38
|
+
const CAMERA_SOURCE=exports.CAMERA_SOURCE={CAMERA:"camera",FILE_PICKER:"file_picker"};// Response status constants
|
|
21
39
|
const RESPONSE_STATUS=exports.RESPONSE_STATUS={SUCCESS:"SUCCESS",ERROR:"ERROR",CANCELLED:"CANCELLED"};// Utility functions for interface validation
|
|
22
40
|
const isValidCommand=command=>ALL_COMMANDS.includes(command);exports.isValidCommand=isValidCommand;const isValidCallback=callback=>ALL_CALLBACKS.includes(callback);exports.isValidCallback=isValidCallback;const isValidInterface=interfaceName=>ALL_INTERFACES.includes(interfaceName);// Get interfaces by category
|
|
23
41
|
exports.isValidInterface=isValidInterface;const getInterfacesByCategory=category=>{const categoryData=INTERFACE_CATEGORIES[category.toUpperCase()];if(!categoryData){throw new Error(`Invalid category: ${category}`);}return categoryData;};// Debug helper to list all interfaces
|
|
24
|
-
exports.getInterfacesByCategory=getInterfacesByCategory;const debugInterfaces=()=>{console.group("🌉 Native Bridge Interfaces");console.log("Commands:",ALL_COMMANDS);console.log("Callbacks:",ALL_CALLBACKS);console.log("Categories:",Object.keys(INTERFACE_CATEGORIES));console.groupEnd();};exports.debugInterfaces=debugInterfaces;var _default=exports.default={NATIVE_COMMANDS,NATIVE_CALLBACKS,INTERFACE_CATEGORIES,ALL_COMMANDS,ALL_CALLBACKS,ALL_INTERFACES,PERMISSION_STATUS,HAPTIC_FEEDBACK_TYPES,FILE_PICKER_STATES,INTENT_STATES,RESPONSE_STATUS,isValidCommand,isValidCallback,isValidInterface,getInterfacesByCategory,debugInterfaces};
|
|
42
|
+
exports.getInterfacesByCategory=getInterfacesByCategory;const debugInterfaces=()=>{console.group("🌉 Native Bridge Interfaces");console.log("Commands:",ALL_COMMANDS);console.log("Callbacks:",ALL_CALLBACKS);console.log("Categories:",Object.keys(INTERFACE_CATEGORIES));console.groupEnd();};exports.debugInterfaces=debugInterfaces;var _default=exports.default={NATIVE_COMMANDS,NATIVE_CALLBACKS,INTERFACE_CATEGORIES,ALL_COMMANDS,ALL_CALLBACKS,ALL_INTERFACES,PERMISSION_STATUS,HAPTIC_FEEDBACK_TYPES,FILE_PICKER_STATES,INTENT_STATES,CAMERA_QUALITY,CAMERA_FORMAT,CAMERA_DEVICE,CAMERA_FLASH_MODE,TRANSPORT_TYPES,CAMERA_SOURCE,RESPONSE_STATUS,isValidCommand,isValidCallback,isValidInterface,getInterfacesByCategory,debugInterfaces};
|
|
@@ -22,7 +22,7 @@ const ERROR_DEFINITIONS=exports.ERROR_DEFINITIONS={[ERROR_CODES.PERMISSION_DENIE
|
|
|
22
22
|
* Translate native error to standardized error
|
|
23
23
|
* @param {any} nativeError - Native error from Android/iOS
|
|
24
24
|
* @returns {Object} Standardized error object
|
|
25
|
-
*/exports.createStandardError=createStandardError;const translateError=nativeError=>{if(!nativeError){return createStandardError(ERROR_CODES.INTERNAL_ERROR,null,nativeError);}const errorString=nativeError.toString().toLowerCase()
|
|
25
|
+
*/exports.createStandardError=createStandardError;const translateError=nativeError=>{if(!nativeError){return createStandardError(ERROR_CODES.INTERNAL_ERROR,null,nativeError);}const errorString=nativeError.toString().toLowerCase();if(errorString.includes("disabled")&&errorString.includes("config")){return createStandardError(ERROR_CODES.FEATURE_UNSUPPORTED,nativeError.toString(),nativeError);}// Permission errors
|
|
26
26
|
if(errorString.includes("permission")&&errorString.includes("denied")){if(errorString.includes("camera")){return createStandardError(ERROR_CODES.PERMISSION_DENIED,"Camera permission denied",nativeError);}if(errorString.includes("storage")||errorString.includes("external_storage")){return createStandardError(ERROR_CODES.PERMISSION_DENIED,"Storage permission denied",nativeError);}return createStandardError(ERROR_CODES.PERMISSION_DENIED,null,nativeError);}// File system errors
|
|
27
27
|
if(errorString.includes("filenotfound")||errorString.includes("file not found")){return createStandardError(ERROR_CODES.FILE_NOT_FOUND,null,nativeError);}if(errorString.includes("storage")&&errorString.includes("full")){return createStandardError(ERROR_CODES.STORAGE_FULL,null,nativeError);}// Network errors
|
|
28
28
|
if(errorString.includes("network")||errorString.includes("connection")||errorString.includes("internet")){return createStandardError(ERROR_CODES.NETWORK_UNAVAILABLE,null,nativeError);}// User cancellation
|