manager: redo fetchAppList onCreate
This commit is contained in:
@@ -2,8 +2,10 @@ package com.sukisu.ultra
|
||||
|
||||
import android.app.Application
|
||||
import android.system.Os
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.ViewModelStore
|
||||
import androidx.lifecycle.ViewModelStoreOwner
|
||||
import me.weishu.kernelsu.ui.viewmodel.SuperUserViewModel
|
||||
import okhttp3.Cache
|
||||
import okhttp3.OkHttpClient
|
||||
import java.io.File
|
||||
@@ -20,6 +22,9 @@ class KernelSUApplication : Application(), ViewModelStoreOwner {
|
||||
super.onCreate()
|
||||
ksuApp = this
|
||||
|
||||
val superUserViewModel = ViewModelProvider(this)[SuperUserViewModel::class.java]
|
||||
superUserViewModel.loadAppList()
|
||||
|
||||
val webroot = File(dataDir, "webroot")
|
||||
if (!webroot.exists()) {
|
||||
webroot.mkdir()
|
||||
|
||||
@@ -81,14 +81,11 @@ import top.yukonga.miuix.kmp.basic.BasicComponent
|
||||
import top.yukonga.miuix.kmp.basic.Card
|
||||
import top.yukonga.miuix.kmp.basic.CardDefaults
|
||||
import top.yukonga.miuix.kmp.basic.Icon
|
||||
import top.yukonga.miuix.kmp.basic.IconButton
|
||||
import top.yukonga.miuix.kmp.basic.MiuixScrollBehavior
|
||||
import top.yukonga.miuix.kmp.basic.Scaffold
|
||||
import top.yukonga.miuix.kmp.basic.ScrollBehavior
|
||||
import top.yukonga.miuix.kmp.basic.Text
|
||||
import top.yukonga.miuix.kmp.basic.TopAppBar
|
||||
import top.yukonga.miuix.kmp.icon.MiuixIcons
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.Save
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme.colorScheme
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme.isDynamicColor
|
||||
@@ -284,18 +281,6 @@ private fun TopBar(
|
||||
color = Color.Transparent,
|
||||
title = stringResource(R.string.app_name),
|
||||
actions = {
|
||||
if (kernelVersion.isGKI()) {
|
||||
IconButton(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
onClick = onInstallClick,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = MiuixIcons.Useful.Save,
|
||||
contentDescription = stringResource(id = R.string.install),
|
||||
tint = colorScheme.onBackground
|
||||
)
|
||||
}
|
||||
}
|
||||
RebootListPopup(
|
||||
modifier = Modifier.padding(end = 16.dp),
|
||||
)
|
||||
|
||||
@@ -139,7 +139,7 @@ import top.yukonga.miuix.kmp.extra.DropdownImpl
|
||||
import top.yukonga.miuix.kmp.icon.MiuixIcons
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.Delete
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.ImmersionMore
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.New
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.Save
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.Undo
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme.colorScheme
|
||||
import top.yukonga.miuix.kmp.utils.getWindowSize
|
||||
@@ -161,12 +161,18 @@ fun ModulePager(
|
||||
|
||||
val modules = viewModel.moduleList
|
||||
|
||||
LaunchedEffect(navigator) {
|
||||
if (viewModel.moduleList.isEmpty() || viewModel.searchResults.value.isEmpty() || viewModel.isNeedRefresh) {
|
||||
viewModel.checkModuleUpdate = prefs.getBoolean("module_check_update", true)
|
||||
viewModel.sortEnabledFirst = prefs.getBoolean("module_sort_enabled_first", false)
|
||||
viewModel.sortActionFirst = prefs.getBoolean("module_sort_action_first", false)
|
||||
viewModel.fetchModuleList()
|
||||
LaunchedEffect(Unit) {
|
||||
when {
|
||||
viewModel.moduleList.isEmpty() -> {
|
||||
viewModel.checkModuleUpdate = prefs.getBoolean("module_check_update", true)
|
||||
viewModel.sortEnabledFirst = prefs.getBoolean("module_sort_enabled_first", false)
|
||||
viewModel.sortActionFirst = prefs.getBoolean("module_sort_action_first", false)
|
||||
viewModel.fetchModuleList()
|
||||
}
|
||||
|
||||
viewModel.isNeedRefresh -> {
|
||||
viewModel.fetchModuleList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,7 +476,7 @@ fun ModulePager(
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
imageVector = MiuixIcons.Useful.New,
|
||||
imageVector = MiuixIcons.Useful.Save,
|
||||
tint = colorScheme.onSurface,
|
||||
contentDescription = stringResource(id = R.string.settings)
|
||||
)
|
||||
|
||||
@@ -90,7 +90,7 @@ import top.yukonga.miuix.kmp.basic.TopAppBar
|
||||
import top.yukonga.miuix.kmp.basic.rememberPullToRefreshState
|
||||
import top.yukonga.miuix.kmp.icon.MiuixIcons
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.Back
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.Redo
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.NavigatorSwitch
|
||||
import top.yukonga.miuix.kmp.icon.icons.useful.Save
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme.colorScheme
|
||||
import top.yukonga.miuix.kmp.utils.PressFeedbackType
|
||||
@@ -563,7 +563,7 @@ fun ModuleRepoDetailScreen(
|
||||
onClick = { uriHandler.openUri(module.homepageUrl) }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = MiuixIcons.Useful.Redo,
|
||||
imageVector = MiuixIcons.Useful.NavigatorSwitch,
|
||||
contentDescription = null,
|
||||
tint = colorScheme.onBackground
|
||||
)
|
||||
|
||||
@@ -115,10 +115,10 @@ fun SuperUserPager(
|
||||
val context = LocalContext.current
|
||||
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
|
||||
LaunchedEffect(navigator) {
|
||||
if (viewModel.appList.value.isEmpty() || viewModel.searchResults.value.isEmpty()) {
|
||||
LaunchedEffect(Unit) {
|
||||
if (viewModel.appList.value.isEmpty() || viewModel.isRefreshing) {
|
||||
viewModel.showSystemApps = prefs.getBoolean("show_system_apps", false)
|
||||
viewModel.fetchAppList()
|
||||
viewModel.loadAppList()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ fun SuperUserPager(
|
||||
LaunchedEffect(isRefreshing) {
|
||||
if (isRefreshing) {
|
||||
delay(350)
|
||||
viewModel.fetchAppList()
|
||||
viewModel.loadAppList()
|
||||
isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,13 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.topjohnwu.superuser.ipc.RootService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -65,6 +69,7 @@ class SuperUserViewModel : ViewModel() {
|
||||
|
||||
private var _appList = mutableStateOf<List<AppInfo>>(emptyList())
|
||||
val appList: State<List<AppInfo>> = _appList
|
||||
|
||||
private val _searchStatus = mutableStateOf(SearchStatus(""))
|
||||
val searchStatus: State<SearchStatus> = _searchStatus
|
||||
|
||||
@@ -122,13 +127,7 @@ class SuperUserViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
if (_searchResults.value == result) {
|
||||
fetchAppList()
|
||||
updateSearchText(text)
|
||||
} else {
|
||||
_searchResults.value = result
|
||||
|
||||
}
|
||||
_searchResults.value = result
|
||||
_searchStatus.value.resultStatus = if (result.isEmpty()) {
|
||||
SearchStatus.ResultStatus.EMPTY
|
||||
} else {
|
||||
@@ -236,4 +235,10 @@ class SuperUserViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadAppList() {
|
||||
viewModelScope.launch {
|
||||
fetchAppList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.webkit.WebViewAssetLoader
|
||||
import com.topjohnwu.superuser.Shell
|
||||
@@ -57,11 +56,10 @@ class WebUIActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
val superUserViewModel = ViewModelProvider(this)[SuperUserViewModel::class.java]
|
||||
|
||||
lifecycleScope.launch {
|
||||
superUserViewModel.fetchAppList()
|
||||
setupWebView()
|
||||
if (SuperUserViewModel.apps.isNotEmpty()) {
|
||||
setupWebView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user