lint
This commit is contained in:
+46
-41
@@ -14,52 +14,57 @@ class ExpoBlueskyReferrerModule : Module() {
|
|||||||
private var intent: Intent? = null
|
private var intent: Intent? = null
|
||||||
private var activityReferrer: Uri? = null
|
private var activityReferrer: Uri? = null
|
||||||
|
|
||||||
override fun definition() = ModuleDefinition {
|
override fun definition() =
|
||||||
Name("ExpoBlueskyReferrer")
|
ModuleDefinition {
|
||||||
|
Name("ExpoBlueskyReferrer")
|
||||||
|
|
||||||
OnNewIntent {
|
OnNewIntent {
|
||||||
intent = it
|
intent = it
|
||||||
activityReferrer = appContext.currentActivity?.referrer
|
activityReferrer = appContext.currentActivity?.referrer
|
||||||
}
|
|
||||||
|
|
||||||
AsyncFunction("getReferrerInfoAsync") {
|
|
||||||
val intentReferrer = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
intent?.getParcelableExtra(Intent.EXTRA_REFERRER, Uri::class.java)
|
|
||||||
} else {
|
|
||||||
intent?.getParcelableExtra(Intent.EXTRA_REFERRER)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some apps explicitly set a referrer, like Chrome. In these cases, we prefer this since
|
AsyncFunction("getReferrerInfoAsync") {
|
||||||
// it's the actual website that the user came from rather than the app.
|
val intentReferrer =
|
||||||
if (intentReferrer is Uri) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
val res = mapOf(
|
intent?.getParcelableExtra(Intent.EXTRA_REFERRER, Uri::class.java)
|
||||||
"referrer" to intentReferrer.toString(),
|
} else {
|
||||||
"hostname" to intentReferrer.host,
|
intent?.getParcelableExtra(Intent.EXTRA_REFERRER)
|
||||||
)
|
}
|
||||||
intent = null
|
|
||||||
return@AsyncFunction res
|
// Some apps explicitly set a referrer, like Chrome. In these cases, we prefer this since
|
||||||
|
// it's the actual website that the user came from rather than the app.
|
||||||
|
if (intentReferrer is Uri) {
|
||||||
|
val res =
|
||||||
|
mapOf(
|
||||||
|
"referrer" to intentReferrer.toString(),
|
||||||
|
"hostname" to intentReferrer.host,
|
||||||
|
)
|
||||||
|
intent = null
|
||||||
|
return@AsyncFunction res
|
||||||
|
}
|
||||||
|
|
||||||
|
// In all other cases, we'll just record the app that sent the intent.
|
||||||
|
if (activityReferrer != null) {
|
||||||
|
// referrer could become null here. `.toString()` though can be called on null
|
||||||
|
val res =
|
||||||
|
mapOf(
|
||||||
|
"referrer" to activityReferrer.toString(),
|
||||||
|
"hostname" to (activityReferrer?.host ?: ""),
|
||||||
|
)
|
||||||
|
activityReferrer = null
|
||||||
|
return@AsyncFunction res
|
||||||
|
}
|
||||||
|
|
||||||
|
return@AsyncFunction null
|
||||||
}
|
}
|
||||||
|
|
||||||
// In all other cases, we'll just record the app that sent the intent.
|
AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise ->
|
||||||
if (activityReferrer != null) {
|
val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build()
|
||||||
// referrer could become null here. `.toString()` though can be called on null
|
referrerClient.startConnection(
|
||||||
val res = mapOf(
|
object : InstallReferrerStateListener {
|
||||||
"referrer" to activityReferrer.toString(),
|
override fun onInstallReferrerSetupFinished(responseCode: Int) {
|
||||||
"hostname" to (activityReferrer?.host ?: ""),
|
if (responseCode == InstallReferrerClient.InstallReferrerResponse.OK) {
|
||||||
)
|
Log.d("ExpoGooglePlayReferrer", "Successfully retrieved referrer info.")
|
||||||
activityReferrer = null
|
|
||||||
return@AsyncFunction res
|
|
||||||
}
|
|
||||||
|
|
||||||
return@AsyncFunction null
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise ->
|
|
||||||
val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build()
|
|
||||||
referrerClient.startConnection(object : InstallReferrerStateListener {
|
|
||||||
override fun onInstallReferrerSetupFinished(responseCode: Int) {
|
|
||||||
if (responseCode == InstallReferrerClient.InstallReferrerResponse.OK) {
|
|
||||||
Log.d("ExpoGooglePlayReferrer", "Successfully retrieved referrer info.")
|
|
||||||
|
|
||||||
val response = referrerClient.installReferrer
|
val response = referrerClient.installReferrer
|
||||||
Log.d("ExpoGooglePlayReferrer", "Install referrer: ${response.installReferrer}")
|
Log.d("ExpoGooglePlayReferrer", "Install referrer: ${response.installReferrer}")
|
||||||
|
|||||||
Reference in New Issue
Block a user