You've already forked KernelSU
mirror of
https://github.com/tiann/KernelSU.git
synced 2025-08-27 23:46:34 +00:00
manager: show loading dialog when uninstall/enable/disable module.
This commit is contained in:
@@ -34,11 +34,14 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.ramcosta.composedestinations.annotation.Destination
|
import com.ramcosta.composedestinations.annotation.Destination
|
||||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import me.weishu.kernelsu.Natives
|
import me.weishu.kernelsu.Natives
|
||||||
import me.weishu.kernelsu.R
|
import me.weishu.kernelsu.R
|
||||||
import me.weishu.kernelsu.ui.component.ConfirmDialog
|
import me.weishu.kernelsu.ui.component.ConfirmDialog
|
||||||
import me.weishu.kernelsu.ui.component.ConfirmResult
|
import me.weishu.kernelsu.ui.component.ConfirmResult
|
||||||
|
import me.weishu.kernelsu.ui.component.LoadingDialog
|
||||||
import me.weishu.kernelsu.ui.screen.destinations.InstallScreenDestination
|
import me.weishu.kernelsu.ui.screen.destinations.InstallScreenDestination
|
||||||
import me.weishu.kernelsu.ui.util.*
|
import me.weishu.kernelsu.ui.util.*
|
||||||
import me.weishu.kernelsu.ui.viewmodel.ModuleViewModel
|
import me.weishu.kernelsu.ui.viewmodel.ModuleViewModel
|
||||||
@@ -95,6 +98,8 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
|||||||
|
|
||||||
ConfirmDialog()
|
ConfirmDialog()
|
||||||
|
|
||||||
|
LoadingDialog()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
hasMagisk -> {
|
hasMagisk -> {
|
||||||
Box(
|
Box(
|
||||||
@@ -153,7 +158,12 @@ private fun ModuleList(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val success = uninstallModule(module.id)
|
val success = dialogHost.withLoading {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
uninstallModule(module.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
viewModel.fetchModuleList()
|
viewModel.fetchModuleList()
|
||||||
}
|
}
|
||||||
@@ -214,10 +224,14 @@ private fun ModuleList(
|
|||||||
ModuleItem(module, isChecked, updateUrl, onUninstall = {
|
ModuleItem(module, isChecked, updateUrl, onUninstall = {
|
||||||
scope.launch { onModuleUninstall(module) }
|
scope.launch { onModuleUninstall(module) }
|
||||||
}, onCheckChanged = {
|
}, onCheckChanged = {
|
||||||
val success = toggleModule(module.id, !isChecked)
|
scope.launch {
|
||||||
if (success) {
|
val success = dialogHost.withLoading {
|
||||||
isChecked = it
|
withContext(Dispatchers.IO) {
|
||||||
scope.launch {
|
toggleModule(module.id, !isChecked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (success) {
|
||||||
|
isChecked = it
|
||||||
viewModel.fetchModuleList()
|
viewModel.fetchModuleList()
|
||||||
|
|
||||||
val result = snackBarHost.showSnackbar(
|
val result = snackBarHost.showSnackbar(
|
||||||
@@ -226,10 +240,10 @@ private fun ModuleList(
|
|||||||
if (result == SnackbarResult.ActionPerformed) {
|
if (result == SnackbarResult.ActionPerformed) {
|
||||||
reboot()
|
reboot()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
val message = if (isChecked) failedDisable else failedEnable
|
||||||
|
snackBarHost.showSnackbar(message.format(module.name))
|
||||||
}
|
}
|
||||||
} else scope.launch {
|
|
||||||
val message = if (isChecked) failedDisable else failedEnable
|
|
||||||
snackBarHost.showSnackbar(message.format(module.name))
|
|
||||||
}
|
}
|
||||||
}, onUpdate = {
|
}, onUpdate = {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user