mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-18 11:31:12 -05:00
fix: Android build changes + close survey window on js exception (#5016)
This commit is contained in:
committed by
GitHub
parent
673f61be17
commit
3ee8485ef0
@@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
kotlin("kapt")
|
||||
}
|
||||
|
||||
@@ -36,7 +35,6 @@ android {
|
||||
jvmTarget = "11"
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
dataBinding = true
|
||||
}
|
||||
}
|
||||
@@ -45,12 +43,6 @@ dependencies {
|
||||
implementation(project(":formbricksSDK"))
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.androidx.ui)
|
||||
implementation(libs.androidx.ui.graphics)
|
||||
implementation(libs.androidx.ui.tooling.preview)
|
||||
implementation(libs.androidx.material3)
|
||||
implementation(libs.androidx.fragment.ktx)
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.material)
|
||||
@@ -59,8 +51,4 @@ dependencies {
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
androidTestImplementation(platform(libs.androidx.compose.bom))
|
||||
androidTestImplementation(libs.androidx.ui.test.junit4)
|
||||
debugImplementation(libs.androidx.ui.tooling)
|
||||
debugImplementation(libs.androidx.ui.test.manifest)
|
||||
}
|
||||
@@ -2,6 +2,5 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application) apply false
|
||||
alias(libs.plugins.kotlin.android) apply false
|
||||
alias(libs.plugins.kotlin.compose) apply false
|
||||
alias(libs.plugins.android.library) apply false
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.formbricks.formbrickssdk.model.environment
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonIgnoreUnknownKeys
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@Serializable
|
||||
@JsonIgnoreUnknownKeys
|
||||
data class Segment(
|
||||
@SerializedName("id") val id: String? = null,
|
||||
@SerializedName("createdAt") val createdAt: String? = null,
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.formbricks.formbrickssdk.model.environment
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonIgnoreUnknownKeys
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@Serializable
|
||||
@JsonIgnoreUnknownKeys
|
||||
data class Styling(
|
||||
@SerializedName("roundness") val roundness: Double? = null,
|
||||
@SerializedName("allowStyleOverwrite") val allowStyleOverwrite: Boolean? = null,
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.formbricks.formbrickssdk.model.environment
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonIgnoreUnknownKeys
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@Serializable
|
||||
@JsonIgnoreUnknownKeys
|
||||
data class Trigger(
|
||||
@SerializedName("actionClass") val actionClass: ActionClassReference?
|
||||
)
|
||||
@@ -8,4 +8,5 @@ enum class EventType {
|
||||
@SerializedName("onDisplayCreated") ON_DISPLAY_CREATED,
|
||||
@SerializedName("onResponseCreated") ON_RESPONSE_CREATED,
|
||||
@SerializedName("onFilePick") ON_FILE_PICK,
|
||||
@SerializedName("onSurveyLibraryLoadError") ON_SURVEY_LIBRARY_LOAD_ERROR
|
||||
}
|
||||
@@ -75,6 +75,9 @@ class FormbricksFragment : BottomSheetDialogFragment() {
|
||||
resultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
override fun onSurveyLibraryLoadError() {
|
||||
dismiss()
|
||||
}
|
||||
})
|
||||
|
||||
var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
@@ -156,6 +159,9 @@ class FormbricksFragment : BottomSheetDialogFragment() {
|
||||
it.webChromeClient = object : WebChromeClient() {
|
||||
override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
|
||||
consoleMessage?.let { cm ->
|
||||
if (cm.messageLevel() == ConsoleMessage.MessageLevel.ERROR) {
|
||||
dismiss()
|
||||
}
|
||||
val log = "[CONSOLE:${cm.messageLevel()}] \"${cm.message()}\", source: ${cm.sourceId()} (${cm.lineNumber()})"
|
||||
Logger.d(log)
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ class FormbricksViewModel : ViewModel() {
|
||||
script.async = true;
|
||||
script.onload = () => loadSurvey();
|
||||
script.onerror = (error) => {
|
||||
FormbricksJavascript.message(JSON.stringify({ event: "onSurveyLibraryLoadError" }));
|
||||
console.error("Failed to load Formbricks Surveys library:", error);
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
|
||||
@@ -15,6 +15,7 @@ class WebAppInterface(private val callback: WebAppCallback?) {
|
||||
fun onDisplayCreated()
|
||||
fun onResponseCreated()
|
||||
fun onFilePick(data: FileUploadData)
|
||||
fun onSurveyLibraryLoadError()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,6 +33,7 @@ class WebAppInterface(private val callback: WebAppCallback?) {
|
||||
EventType.ON_DISPLAY_CREATED -> callback?.onDisplayCreated()
|
||||
EventType.ON_RESPONSE_CREATED -> callback?.onResponseCreated()
|
||||
EventType.ON_FILE_PICK -> { callback?.onFilePick(FileUploadData.from(data)) }
|
||||
EventType.ON_SURVEY_LIBRARY_LOAD_ERROR -> { callback?.onSurveyLibraryLoadError() }
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.e(e.message)
|
||||
|
||||
@@ -9,8 +9,6 @@ junit = "4.13.2"
|
||||
junitVersion = "1.1.5"
|
||||
espressoCore = "3.5.1"
|
||||
|
||||
activityCompose = "1.8.0"
|
||||
composeBom = "2024.04.01"
|
||||
appcompat = "1.6.1"
|
||||
material = "1.10.0"
|
||||
|
||||
@@ -35,15 +33,6 @@ junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
|
||||
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
|
||||
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
|
||||
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
|
||||
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
|
||||
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
|
||||
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
|
||||
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" }
|
||||
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
|
||||
@@ -66,6 +55,5 @@ androidx-constraintlayout = { group = "androidx.constraintlayout", name = "const
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||
android-library = { id = "com.android.library", version.ref = "agp" }
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@ enum EventType: String, Codable {
|
||||
case onDisplayCreated = "onDisplayCreated"
|
||||
case onResponseCreated = "onResponseCreated"
|
||||
case onOpenExternalURL = "onOpenExternalURL"
|
||||
case onSurveyLibraryLoadError = "onSurveyLibraryLoadError"
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ private extension FormbricksViewModel {
|
||||
script.async = true;
|
||||
script.onload = () => loadSurvey();
|
||||
script.onerror = (error) => {
|
||||
window.webkit.messageHandlers.jsMessage.postMessage(JSON.stringify({ event: "onSurveyLibraryLoadError" }));
|
||||
console.error("Failed to load Formbricks Surveys library:", error);
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
|
||||
@@ -99,6 +99,10 @@ final class JsMessageHandler: NSObject, WKScriptMessageHandler {
|
||||
if let message = try? JSONDecoder().decode(OpenExternalUrlMessage.self, from: data), let url = URL(string: message.onOpenExternalURLParams.url) {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
|
||||
/// Happens when the survey library fails to load.
|
||||
case .onSurveyLibraryLoadError:
|
||||
SurveyManager.shared.dismissSurveyWebView()
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -140,7 +144,8 @@ private extension SurveyWebView {
|
||||
console.debug = function() { log("📘", "debug", arguments); originalDebug.apply(null, arguments) }
|
||||
|
||||
window.addEventListener("error", function(e) {
|
||||
log("💥", "Uncaught", [`${e.message} at ${e.filename}:${e.lineno}:${e.colno}`])
|
||||
window.webkit.messageHandlers.jsMessage.postMessage(JSON.stringify({ event: "onSurveyLibraryLoadError" }));
|
||||
log("💥", "Uncaught", [`${e.message} at ${e.filename}:${e.lineno}:${e.colno}`])
|
||||
})
|
||||
"""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user