Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.withContext
import kotlinx.parcelize.Parcelize
import me.weishu.kernelsu.IKsuInterface
Expand All @@ -38,6 +40,9 @@ class SuperUserViewModel : ViewModel() {
private const val TAG = "SuperUserViewModel"
private val appsLock = Any()
var apps by mutableStateOf<List<AppInfo>>(emptyList())

private val _isAppListLoaded = MutableStateFlow(false)
val isAppListLoaded = _isAppListLoaded.asStateFlow()

@JvmStatic
fun getAppIconDrawable(context: Context, packageName: String): Drawable? {
Expand Down Expand Up @@ -185,6 +190,7 @@ class SuperUserViewModel : ViewModel() {

synchronized(appsLock) {
apps = newApps
_isAppListLoaded.value = true
}

val comparator = compareBy<AppInfo> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ object AppIconUtil {
val drawable = getAppIconDrawable(context, packageName) ?: return null
val raw = drawableToBitmap(drawable, sizePx)
val icon = raw.scale(sizePx, sizePx)
if (raw != icon) raw.recycle()
iconCache.put(packageName, icon)
return icon
} catch (_: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@ import android.webkit.WebResourceResponse
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.lifecycleScope
import androidx.webkit.WebViewAssetLoader
import kotlinx.coroutines.launch
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import me.weishu.kernelsu.ui.util.createRootShell
import me.weishu.kernelsu.ui.viewmodel.SuperUserViewModel
import top.yukonga.miuix.kmp.basic.InfiniteProgressIndicator
import java.io.File

@SuppressLint("SetJavaScriptEnabled")
class WebUIActivity : ComponentActivity() {
private lateinit var webviewInterface: WebViewInterface

private var rootShell: Shell? = null
private val superUserViewModel: SuperUserViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {

Expand All @@ -40,10 +45,22 @@ class WebUIActivity : ComponentActivity() {

super.onCreate(savedInstanceState)

setContent {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
InfiniteProgressIndicator()
}
}

lifecycleScope.launch {
superUserViewModel.fetchAppList()
SuperUserViewModel.isAppListLoaded.first { it }
setupWebView()
}
}

private fun setupWebView() {
val moduleId = intent.getStringExtra("id")!!
val name = intent.getStringExtra("name")!!
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
Expand Down