You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
72 lines
2.1 KiB
Kotlin
72 lines
2.1 KiB
Kotlin
package com.rifsxd.ksunext
|
|
|
|
import android.app.Application
|
|
import android.system.Os
|
|
import coil.Coil
|
|
import coil.ImageLoader
|
|
import com.dergoogler.mmrl.platform.Platform
|
|
import me.zhanghai.android.appiconloader.coil.AppIconFetcher
|
|
import me.zhanghai.android.appiconloader.coil.AppIconKeyer
|
|
import okhttp3.Cache
|
|
import okhttp3.OkHttpClient
|
|
import java.io.File
|
|
import java.util.Locale
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.GlobalScope
|
|
import kotlinx.coroutines.launch
|
|
import com.rifsxd.ksunext.ui.webui.initPlatform
|
|
|
|
lateinit var ksuApp: KernelSUApplication
|
|
|
|
class KernelSUApplication : Application() {
|
|
|
|
lateinit var okhttpClient: OkHttpClient
|
|
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
ksuApp = this
|
|
|
|
Platform.setHiddenApiExemptions()
|
|
|
|
// Pre-initialize WX Platform as early as possible
|
|
launchPlatformInit()
|
|
|
|
val context = this
|
|
val iconSize = resources.getDimensionPixelSize(android.R.dimen.app_icon_size)
|
|
Coil.setImageLoader(
|
|
ImageLoader.Builder(context)
|
|
.components {
|
|
add(AppIconKeyer())
|
|
add(AppIconFetcher.Factory(iconSize, false, context))
|
|
}
|
|
.build()
|
|
)
|
|
|
|
val webroot = File(dataDir, "webroot")
|
|
if (!webroot.exists()) {
|
|
webroot.mkdir()
|
|
}
|
|
|
|
// Provide working env for rust's temp_dir()
|
|
Os.setenv("TMPDIR", cacheDir.absolutePath, true)
|
|
|
|
okhttpClient =
|
|
OkHttpClient.Builder().cache(Cache(File(cacheDir, "okhttp"), 10 * 1024 * 1024))
|
|
.addInterceptor { block ->
|
|
block.proceed(
|
|
block.request().newBuilder()
|
|
.header("User-Agent", "KernelSU/${BuildConfig.VERSION_CODE}")
|
|
.header("Accept-Language", Locale.getDefault().toLanguageTag()).build()
|
|
)
|
|
}.build()
|
|
}
|
|
|
|
private fun launchPlatformInit() {
|
|
// Use a coroutine to avoid blocking the main thread
|
|
GlobalScope.launch(Dispatchers.IO) {
|
|
initPlatform()
|
|
}
|
|
}
|
|
|
|
}
|