manager: fix webui package manager
Co-authored-by: KOWX712 <leecc0503@gmail.com> Co-authored-by: YuKongA <70465933+YuKongA@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,8 @@ import java.util.concurrent.TimeUnit
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
import com.sukisu.zako.IKsuInterface
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@@ -59,7 +61,8 @@ class SuperUserViewModel : ViewModel() {
|
||||
private const val TAG = "SuperUserViewModel"
|
||||
private val appsLock = Any()
|
||||
var apps by mutableStateOf<List<AppInfo>>(emptyList())
|
||||
var appGroups by mutableStateOf<List<AppGroup>>(emptyList())
|
||||
private val _isAppListLoaded = MutableStateFlow(false)
|
||||
val isAppListLoaded = _isAppListLoaded.asStateFlow()
|
||||
|
||||
@JvmStatic
|
||||
fun getAppIconDrawable(context: Context, packageName: String): Drawable? {
|
||||
@@ -68,6 +71,8 @@ class SuperUserViewModel : ViewModel() {
|
||||
?.packageInfo?.applicationInfo?.loadIcon(context.packageManager)
|
||||
}
|
||||
|
||||
var appGroups by mutableStateOf<List<AppGroup>>(emptyList())
|
||||
|
||||
private const val PREFS_NAME = "settings"
|
||||
private const val KEY_SHOW_SYSTEM_APPS = "show_system_apps"
|
||||
private const val KEY_SELECTED_CATEGORY = "selected_category"
|
||||
@@ -337,6 +342,10 @@ class SuperUserViewModel : ViewModel() {
|
||||
|
||||
stopKsuService()
|
||||
|
||||
synchronized(appsLock) {
|
||||
_isAppListLoaded.value = true
|
||||
}
|
||||
|
||||
appListMutex.withLock {
|
||||
val filteredApps = result.filter { it.packageName != ksuApp.packageName }
|
||||
apps = filteredApps
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -10,8 +10,14 @@ 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.material3.CircularProgressIndicator
|
||||
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
|
||||
@@ -21,13 +27,13 @@ import com.dergoogler.mmrl.platform.model.ModId
|
||||
import com.dergoogler.mmrl.webui.interfaces.WXOptions
|
||||
import com.sukisu.ultra.ui.util.createRootShell
|
||||
import com.sukisu.ultra.ui.viewmodel.SuperUserViewModel
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
class WebUIActivity : ComponentActivity() {
|
||||
private val rootShell by lazy { createRootShell(true) }
|
||||
private val superUserViewModel: SuperUserViewModel by viewModels()
|
||||
private var webView = null as WebView?
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -40,10 +46,21 @@ class WebUIActivity : ComponentActivity() {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
lifecycleScope.launch {
|
||||
superUserViewModel.fetchAppList()
|
||||
setContent {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
SuperUserViewModel.isAppListLoaded.first { it }
|
||||
setupWebView()
|
||||
}
|
||||
}
|
||||
private fun setupWebView() {
|
||||
val moduleId = intent.getStringExtra("id") ?: finishAndRemoveTask().let { return }
|
||||
val name = intent.getStringExtra("name") ?: finishAndRemoveTask().let { return }
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||
|
||||
Reference in New Issue
Block a user