manager: make inset synchronize
This commit is contained in:
@@ -22,7 +22,9 @@ import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.webkit.WebViewAssetLoader
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import kotlinx.coroutines.CancellableContinuation
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import com.sukisu.ultra.ui.util.createRootShell
|
||||
import com.sukisu.ultra.ui.viewmodel.SuperUserViewModel
|
||||
import top.yukonga.miuix.kmp.basic.InfiniteProgressIndicator
|
||||
@@ -34,6 +36,7 @@ class WebUIActivity : ComponentActivity() {
|
||||
|
||||
private var rootShell: Shell? = null
|
||||
private lateinit var insets: Insets
|
||||
private var insetsContinuation: CancellableContinuation<Unit>? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
@@ -62,7 +65,7 @@ class WebUIActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupWebView() {
|
||||
private suspend fun setupWebView() {
|
||||
val moduleId = intent.getStringExtra("id")!!
|
||||
val name = intent.getStringExtra("name")!!
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||
@@ -81,6 +84,35 @@ class WebUIActivity : ComponentActivity() {
|
||||
val rootShell = createRootShell(true).also { this.rootShell = it }
|
||||
insets = Insets(0, 0, 0, 0)
|
||||
|
||||
val webView = WebView(this).apply {
|
||||
setBackgroundColor(Color.TRANSPARENT)
|
||||
val density = resources.displayMetrics.density
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this) { _, windowInsets ->
|
||||
val inset = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
|
||||
insets = Insets(
|
||||
top = (inset.top / density).toInt(),
|
||||
bottom = (inset.bottom / density).toInt(),
|
||||
left = (inset.left / density).toInt(),
|
||||
right = (inset.right / density).toInt()
|
||||
)
|
||||
insetsContinuation?.resumeWith(Result.success(Unit))
|
||||
insetsContinuation = null
|
||||
WindowInsetsCompat.CONSUMED
|
||||
}
|
||||
}
|
||||
|
||||
setContentView(webView)
|
||||
|
||||
if (insets == Insets(0, 0, 0, 0)) {
|
||||
suspendCancellableCoroutine<Unit> { cont ->
|
||||
insetsContinuation = cont
|
||||
cont.invokeOnCancellation {
|
||||
insetsContinuation = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val webViewAssetLoader = WebViewAssetLoader.Builder()
|
||||
.setDomain("mui.kernelsu.org")
|
||||
.addPathHandler(
|
||||
@@ -114,30 +146,15 @@ class WebUIActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
val webView = WebView(this).apply {
|
||||
setBackgroundColor(Color.TRANSPARENT)
|
||||
val density = resources.displayMetrics.density
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this) { _, windowInsets ->
|
||||
val inset = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
|
||||
insets = Insets(
|
||||
top = (inset.top / density).toInt(),
|
||||
bottom = (inset.bottom / density).toInt(),
|
||||
left = (inset.left / density).toInt(),
|
||||
right = (inset.right / density).toInt()
|
||||
)
|
||||
WindowInsetsCompat.CONSUMED
|
||||
}
|
||||
webView.apply {
|
||||
settings.javaScriptEnabled = true
|
||||
settings.domStorageEnabled = true
|
||||
settings.allowFileAccess = false
|
||||
webviewInterface = WebViewInterface(this@WebUIActivity, this, moduleDir)
|
||||
webviewInterface = WebViewInterface(this@WebUIActivity, webView, moduleDir)
|
||||
addJavascriptInterface(webviewInterface, "ksu")
|
||||
setWebViewClient(webViewClient)
|
||||
loadUrl("https://mui.kernelsu.org/index.html")
|
||||
}
|
||||
|
||||
setContentView(webView)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
Reference in New Issue
Block a user