finish migration
This commit is contained in:
+39
@@ -1,5 +1,8 @@
|
|||||||
package expo.modules.blueskyswissarmy.referrer
|
package expo.modules.blueskyswissarmy.referrer
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.android.installreferrer.api.InstallReferrerClient
|
import com.android.installreferrer.api.InstallReferrerClient
|
||||||
import com.android.installreferrer.api.InstallReferrerStateListener
|
import com.android.installreferrer.api.InstallReferrerStateListener
|
||||||
@@ -8,9 +11,45 @@ import expo.modules.kotlin.modules.ModuleDefinition
|
|||||||
import expo.modules.kotlin.Promise
|
import expo.modules.kotlin.Promise
|
||||||
|
|
||||||
class ExpoBlueskyReferrerModule : Module() {
|
class ExpoBlueskyReferrerModule : Module() {
|
||||||
|
private var intent: Intent? = null
|
||||||
|
private var activityReferrer: Uri? = null
|
||||||
|
|
||||||
override fun definition() = ModuleDefinition {
|
override fun definition() = ModuleDefinition {
|
||||||
Name("ExpoBlueskyReferrer")
|
Name("ExpoBlueskyReferrer")
|
||||||
|
|
||||||
|
OnNewIntent {
|
||||||
|
intent = it
|
||||||
|
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
|
||||||
|
// it's the actual website that the user came from rather than the app.
|
||||||
|
if (intentReferrer is Uri) {
|
||||||
|
return@AsyncFunction mapOf(
|
||||||
|
"referrer" to intentReferrer.toString(),
|
||||||
|
"hostname" to intentReferrer.host,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
return@AsyncFunction mapOf(
|
||||||
|
"referrer" to activityReferrer.toString(),
|
||||||
|
"hostname" to (activityReferrer?.host ?: ""),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return@AsyncFunction null
|
||||||
|
}
|
||||||
|
|
||||||
AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise ->
|
AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise ->
|
||||||
val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build()
|
val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build()
|
||||||
referrerClient.startConnection(object : InstallReferrerStateListener {
|
referrerClient.startConnection(object : InstallReferrerStateListener {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import {requireNativeModule} from 'expo'
|
import {requireNativeModule} from 'expo'
|
||||||
|
|
||||||
import {GooglePlayReferrerInfo} from './types'
|
import {GooglePlayReferrerInfo, ReferrerInfo} from './types'
|
||||||
|
|
||||||
export const NativeModule = requireNativeModule('ExpoBlueskyReferrer')
|
export const NativeModule = requireNativeModule('ExpoBlueskyReferrer')
|
||||||
|
|
||||||
export function getGooglePlayReferrerInfoAsync(): Promise<GooglePlayReferrerInfo> {
|
export function getGooglePlayReferrerInfoAsync(): Promise<GooglePlayReferrerInfo | null> {
|
||||||
return NativeModule.getGooglePlayReferrerInfoAsync()
|
return NativeModule.getGooglePlayReferrerInfoAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getReferrerInfoAsync(): Promise<ReferrerInfo | null> {
|
||||||
|
return NativeModule.getReferrerInfoAsync()
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import {requireNativeModule} from 'expo'
|
||||||
|
|
||||||
|
import {NotImplementedError} from '../NotImplemented'
|
||||||
|
import {GooglePlayReferrerInfo, ReferrerInfo} from './types'
|
||||||
|
|
||||||
|
export const NativeModule = requireNativeModule('ExpoBlueskyReferrer')
|
||||||
|
|
||||||
|
export function getGooglePlayReferrerInfoAsync(): Promise<GooglePlayReferrerInfo> {
|
||||||
|
throw new NotImplementedError()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getReferrerInfoAsync(): Promise<ReferrerInfo | null> {
|
||||||
|
return NativeModule.getReferrerInfoAsync()
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
import {NotImplementedError} from '../NotImplemented'
|
import {NotImplementedError} from '../NotImplemented'
|
||||||
import {GooglePlayReferrerInfo} from './types'
|
import {GooglePlayReferrerInfo, ReferrerInfo} from './types'
|
||||||
|
|
||||||
// @ts-ignore throws
|
|
||||||
export function getGooglePlayReferrerInfoAsync(): Promise<GooglePlayReferrerInfo> {
|
export function getGooglePlayReferrerInfoAsync(): Promise<GooglePlayReferrerInfo> {
|
||||||
throw new NotImplementedError()
|
throw new NotImplementedError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getReferrerInfoAsync(): Promise<ReferrerInfo | null> {
|
||||||
|
throw new NotImplementedError()
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import {Platform} from 'react-native'
|
||||||
|
|
||||||
|
import {NotImplementedError} from '../NotImplemented'
|
||||||
|
import {GooglePlayReferrerInfo, ReferrerInfo} from './types'
|
||||||
|
|
||||||
|
export function getGooglePlayReferrerInfoAsync(): Promise<GooglePlayReferrerInfo> {
|
||||||
|
throw new NotImplementedError()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getReferrerInfoAsync(): Promise<ReferrerInfo | null> {
|
||||||
|
if (
|
||||||
|
Platform.OS === 'web' &&
|
||||||
|
typeof document !== 'undefined' &&
|
||||||
|
document != null &&
|
||||||
|
document.referrer
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const url = new URL(document.referrer)
|
||||||
|
if (url.hostname !== 'bsky.app') {
|
||||||
|
return {
|
||||||
|
referrer: url.href,
|
||||||
|
hostname: url.hostname,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// If something happens to the URL parsing, we don't want to actually cause any problems for the user. Just
|
||||||
|
// log the error so we might catch it
|
||||||
|
console.error('Failed to parse referrer URL')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
export type GooglePlayReferrerInfo =
|
export type GooglePlayReferrerInfo = {
|
||||||
| {
|
installReferrer?: string
|
||||||
installReferrer?: string
|
clickTimestamp?: number
|
||||||
clickTimestamp?: number
|
installTimestamp?: number
|
||||||
installTimestamp?: number
|
}
|
||||||
}
|
|
||||||
| undefined
|
export type ReferrerInfo = {
|
||||||
|
referrer: string
|
||||||
|
hostname: string
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
apply plugin: 'com.android.library'
|
|
||||||
|
|
||||||
group = 'expo.modules.getreferrer'
|
|
||||||
version = '0.6.0'
|
|
||||||
|
|
||||||
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
||||||
apply from: expoModulesCorePlugin
|
|
||||||
applyKotlinExpoModulesCorePlugin()
|
|
||||||
useCoreDependencies()
|
|
||||||
useExpoPublishing()
|
|
||||||
|
|
||||||
// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
|
|
||||||
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
|
|
||||||
// Most of the time, you may like to manage the Android SDK versions yourself.
|
|
||||||
def useManagedAndroidSdkVersions = false
|
|
||||||
if (useManagedAndroidSdkVersions) {
|
|
||||||
useDefaultAndroidSdkVersions()
|
|
||||||
} else {
|
|
||||||
buildscript {
|
|
||||||
// Simple helper that allows the root project to override versions declared by this library.
|
|
||||||
ext.safeExtGet = { prop, fallback ->
|
|
||||||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
||||||
}
|
|
||||||
}
|
|
||||||
project.android {
|
|
||||||
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
||||||
defaultConfig {
|
|
||||||
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
||||||
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace "expo.modules.getreferrer"
|
|
||||||
defaultConfig {
|
|
||||||
versionCode 1
|
|
||||||
versionName "0.6.0"
|
|
||||||
}
|
|
||||||
lintOptions {
|
|
||||||
abortOnError false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation("com.android.installreferrer:installreferrer:2.2")
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<manifest>
|
|
||||||
</manifest>
|
|
||||||
-86
@@ -1,86 +0,0 @@
|
|||||||
package expo.modules.getreferrer
|
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Build
|
|
||||||
import com.android.installreferrer.api.InstallReferrerClient
|
|
||||||
import com.android.installreferrer.api.InstallReferrerStateListener
|
|
||||||
import expo.modules.kotlin.modules.Module
|
|
||||||
import expo.modules.kotlin.modules.ModuleDefinition
|
|
||||||
import expo.modules.kotlin.Promise
|
|
||||||
|
|
||||||
class ExpoGetReferrerModule : Module() {
|
|
||||||
private var intent: Intent? = null
|
|
||||||
private var activityReferrer: Uri? = null
|
|
||||||
|
|
||||||
override fun definition() = ModuleDefinition {
|
|
||||||
Name("ExpoGetReferrer")
|
|
||||||
|
|
||||||
OnNewIntent {
|
|
||||||
intent = it
|
|
||||||
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
|
|
||||||
// it's the actual website that the user came from rather than the app.
|
|
||||||
if (intentReferrer is Uri) {
|
|
||||||
return@AsyncFunction mapOf(
|
|
||||||
"referrer" to intentReferrer.toString(),
|
|
||||||
"hostname" to intentReferrer.host,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
return@AsyncFunction mapOf(
|
|
||||||
"referrer" to activityReferrer.toString(),
|
|
||||||
"hostname" to (activityReferrer?.host ?: ""),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
val response = referrerClient.installReferrer
|
|
||||||
promise.resolve(
|
|
||||||
mapOf(
|
|
||||||
"installReferrer" to response.installReferrer,
|
|
||||||
"clickTimestamp" to response.referrerClickTimestampSeconds,
|
|
||||||
"installTimestamp" to response.installBeginTimestampSeconds
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
promise.reject(
|
|
||||||
"ERR_GOOGLE_PLAY_REFERRER_UNKNOWN",
|
|
||||||
"Failed to get referrer info",
|
|
||||||
Exception("Failed to get referrer info")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
referrerClient.endConnection()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onInstallReferrerServiceDisconnected() {
|
|
||||||
promise.reject(
|
|
||||||
"ERR_GOOGLE_PLAY_REFERRER_DISCONNECTED",
|
|
||||||
"Failed to get referrer info",
|
|
||||||
Exception("Failed to get referrer info")
|
|
||||||
)
|
|
||||||
referrerClient.endConnection()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"platforms": ["android"],
|
|
||||||
"android": {
|
|
||||||
"modules": ["expo.modules.getreferrer.ExpoGetReferrerModule"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
export type ExpoGetReferrerModule = {
|
|
||||||
getGooglePlayReferrerInfoAsync: () => Promise<GooglePlayReferrerInfo>
|
|
||||||
getReferrerInfoAsync: () => Promise<{
|
|
||||||
referrer: string
|
|
||||||
hostname: string
|
|
||||||
} | null>
|
|
||||||
}
|
|
||||||
|
|
||||||
export type GooglePlayReferrerInfo =
|
|
||||||
| {
|
|
||||||
installReferrer?: string
|
|
||||||
clickTimestamp?: number
|
|
||||||
installTimestamp?: number
|
|
||||||
}
|
|
||||||
| undefined
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import {requireNativeModule} from 'expo-modules-core'
|
|
||||||
|
|
||||||
import {ExpoGetReferrerModule} from './ExpoGetReferrer.types'
|
|
||||||
|
|
||||||
const NativeModule =
|
|
||||||
requireNativeModule<ExpoGetReferrerModule>('ExpoGetReferrer')
|
|
||||||
|
|
||||||
export const GetReferrerModule: ExpoGetReferrerModule = {
|
|
||||||
getGooglePlayReferrerInfoAsync: async () => {
|
|
||||||
console.error('getGooglePlayReferrerInfo is only available on Android')
|
|
||||||
throw new Error('getGooglePlayReferrerInfo is only available on Android')
|
|
||||||
},
|
|
||||||
getReferrerInfoAsync: NativeModule.getReferrerInfoAsync,
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import {requireNativeModule} from 'expo-modules-core'
|
|
||||||
|
|
||||||
import {ExpoGetReferrerModule} from './ExpoGetReferrer.types'
|
|
||||||
|
|
||||||
const NativeModule =
|
|
||||||
requireNativeModule<ExpoGetReferrerModule>('ExpoGetReferrer')
|
|
||||||
|
|
||||||
export const GetReferrerModule: ExpoGetReferrerModule = {
|
|
||||||
getGooglePlayReferrerInfoAsync: NativeModule.getGooglePlayReferrerInfoAsync,
|
|
||||||
getReferrerInfoAsync: NativeModule.getReferrerInfoAsync,
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import {isWeb} from 'platform/detection'
|
|
||||||
import {ExpoGetReferrerModule} from './ExpoGetReferrer.types'
|
|
||||||
|
|
||||||
export const GetReferrerModule: ExpoGetReferrerModule = {
|
|
||||||
getGooglePlayReferrerInfoAsync: async () => {
|
|
||||||
console.error('getReferrerInfoAsync is only available on Android')
|
|
||||||
throw new Error('getGooglePlayReferrerInfo is only available on Android')
|
|
||||||
},
|
|
||||||
getReferrerInfoAsync: async () => {
|
|
||||||
try {
|
|
||||||
if (
|
|
||||||
isWeb &&
|
|
||||||
typeof document !== 'undefined' &&
|
|
||||||
document != null &&
|
|
||||||
document.referrer
|
|
||||||
) {
|
|
||||||
const url = new URL(document.referrer)
|
|
||||||
if (url.hostname !== 'bsky.app') {
|
|
||||||
return {
|
|
||||||
referrer: url.href,
|
|
||||||
hostname: url.hostname,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
},
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user