2025-07-14 17:27:00 +08:00
|
|
|
package com.trust.ywx
|
2025-07-14 14:13:15 +08:00
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
|
import com.facebook.react.PackageList
|
|
|
|
|
import com.facebook.react.ReactApplication
|
|
|
|
|
import com.facebook.react.ReactHost
|
|
|
|
|
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
|
|
|
|
|
import com.facebook.react.ReactNativeHost
|
|
|
|
|
import com.facebook.react.ReactPackage
|
|
|
|
|
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
|
|
|
|
import com.facebook.react.defaults.DefaultReactNativeHost
|
2025-07-14 20:30:51 +08:00
|
|
|
import com.trust.ywx.specs.navigation.NavigationPackage
|
2025-07-16 18:18:35 +08:00
|
|
|
import com.trust.ywx.utils.FileHelper
|
|
|
|
|
import java.io.File
|
2025-07-14 14:13:15 +08:00
|
|
|
|
|
|
|
|
class MainApplication : Application(), ReactApplication {
|
|
|
|
|
|
2025-07-15 12:47:06 +08:00
|
|
|
override val reactNativeHost: ReactNativeHost =
|
|
|
|
|
object : DefaultReactNativeHost(this) {
|
|
|
|
|
override fun getPackages(): List<ReactPackage> =
|
|
|
|
|
PackageList(this).packages.apply {
|
|
|
|
|
// Packages that cannot be autolinked yet can be added manually here, for example:
|
|
|
|
|
add(NavigationPackage())
|
|
|
|
|
}
|
2025-07-14 14:13:15 +08:00
|
|
|
|
2025-07-16 18:40:32 +08:00
|
|
|
override fun getJSMainModuleName(): String =
|
|
|
|
|
if (getUseDeveloperSupport()) "index" else "commom"
|
|
|
|
|
|
|
|
|
|
override fun getBundleAssetName(): String? =
|
|
|
|
|
if (getUseDeveloperSupport()) "index.android.bundle" else null
|
|
|
|
|
|
2025-07-16 18:18:35 +08:00
|
|
|
//
|
|
|
|
|
// override fun getJSBundleFile(): String? = if (getUseDeveloperSupport()) {
|
|
|
|
|
// super.getJSBundleFile()
|
|
|
|
|
// } else {
|
|
|
|
|
// FileHelper.getFilePath("common.android.bundle", this@MainApplication, "bundles")
|
|
|
|
|
// }
|
2025-07-16 18:40:32 +08:00
|
|
|
override fun getJSBundleFile(): String? = if (getUseDeveloperSupport()) {
|
|
|
|
|
null
|
|
|
|
|
} else {
|
2025-07-16 18:18:35 +08:00
|
|
|
FileHelper.getFilePath("common.android.bundle", this@MainApplication, "bundles")
|
2025-07-16 18:40:32 +08:00
|
|
|
}
|
2025-07-14 14:13:15 +08:00
|
|
|
|
2025-07-15 12:47:06 +08:00
|
|
|
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
|
2025-07-14 14:13:15 +08:00
|
|
|
|
2025-07-15 14:47:02 +08:00
|
|
|
override val isNewArchEnabled: Boolean = true
|
|
|
|
|
override val isHermesEnabled: Boolean = true
|
2025-07-15 12:47:06 +08:00
|
|
|
}
|
2025-07-14 14:13:15 +08:00
|
|
|
|
2025-07-15 12:47:06 +08:00
|
|
|
override val reactHost: ReactHost
|
|
|
|
|
get() = getDefaultReactHost(applicationContext, reactNativeHost)
|
|
|
|
|
|
2025-07-16 18:40:32 +08:00
|
|
|
companion object {
|
2025-07-16 18:18:35 +08:00
|
|
|
var isNew = true
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-15 12:47:06 +08:00
|
|
|
override fun onCreate() {
|
2025-07-16 18:18:35 +08:00
|
|
|
val f = File(FileHelper.getDirPath(this, "bundles"))
|
|
|
|
|
val bf = File(FileHelper.getFilePath("bundle.zip", this, "bundles"))
|
|
|
|
|
if (!f.exists() || !f.isDirectory) {
|
|
|
|
|
f.mkdirs()
|
|
|
|
|
}
|
|
|
|
|
if (f.list().size <= 1) {
|
|
|
|
|
bf.delete()
|
|
|
|
|
FileHelper.copyAssetFileToInternalStorage(this, "bundle.zip", bf)
|
|
|
|
|
if (bf.exists()) {
|
|
|
|
|
FileHelper.unzip(bf, f)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-15 12:47:06 +08:00
|
|
|
super.onCreate()
|
|
|
|
|
loadReactNative(this)
|
|
|
|
|
}
|
2025-07-14 14:13:15 +08:00
|
|
|
}
|