You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
manager: added module size label
This commit is contained in:
@@ -896,6 +896,13 @@ fun ModuleItem(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||||
) {
|
) {
|
||||||
|
LabelItem(
|
||||||
|
text = formatSize(module.size),
|
||||||
|
style = com.dergoogler.mmrl.ui.component.LabelItemDefaults.style.copy(
|
||||||
|
containerColor = MaterialTheme.colorScheme.secondaryContainer,
|
||||||
|
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
|
||||||
|
)
|
||||||
|
)
|
||||||
LabelItem(
|
LabelItem(
|
||||||
text = if (module.enabled) stringResource(R.string.enabled) else stringResource(R.string.disabled),
|
text = if (module.enabled) stringResource(R.string.enabled) else stringResource(R.string.disabled),
|
||||||
style = if (module.enabled)
|
style = if (module.enabled)
|
||||||
@@ -935,23 +942,25 @@ fun ModuleItem(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (module.hasWebUi) {
|
if (!module.remove) {
|
||||||
LabelItem(
|
if (module.hasWebUi) {
|
||||||
text = stringResource(R.string.webui),
|
LabelItem(
|
||||||
style = com.dergoogler.mmrl.ui.component.LabelItemDefaults.style.copy(
|
text = stringResource(R.string.webui),
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
style = com.dergoogler.mmrl.ui.component.LabelItemDefaults.style.copy(
|
||||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||||
|
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
if (module.hasActionScript) {
|
||||||
if (module.hasActionScript) {
|
LabelItem(
|
||||||
LabelItem(
|
text = stringResource(R.string.action),
|
||||||
text = stringResource(R.string.action),
|
style = com.dergoogler.mmrl.ui.component.LabelItemDefaults.style.copy(
|
||||||
style = com.dergoogler.mmrl.ui.component.LabelItemDefaults.style.copy(
|
containerColor = MaterialTheme.colorScheme.secondaryContainer,
|
||||||
containerColor = MaterialTheme.colorScheme.secondaryContainer,
|
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
|
||||||
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1036,42 +1045,46 @@ fun ModuleItem(
|
|||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (module.hasWebUi) {
|
if (!module.remove) {
|
||||||
DropdownMenuItem(
|
if (module.hasWebUi) {
|
||||||
text = { Text(stringResource(R.string.webui)) },
|
DropdownMenuItem(
|
||||||
onClick = {
|
text = { Text(stringResource(R.string.webui)) },
|
||||||
expanded = false
|
onClick = {
|
||||||
onClick(module)
|
expanded = false
|
||||||
}
|
onClick(module)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
if (module.hasActionScript) {
|
|
||||||
DropdownMenuItem(
|
|
||||||
text = { Text(stringResource(R.string.action)) },
|
|
||||||
onClick = {
|
|
||||||
expanded = false
|
|
||||||
navigator.navigate(ExecuteModuleActionScreenDestination(module.dirId))
|
|
||||||
viewModel.markNeedRefresh()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (module.hasWebUi || module.hasActionScript ) {
|
|
||||||
HorizontalDivider()
|
|
||||||
}
|
|
||||||
|
|
||||||
DropdownMenuItem(
|
|
||||||
text = {
|
|
||||||
Text(
|
|
||||||
if (module.enabled) stringResource(R.string.disable)
|
|
||||||
else stringResource(R.string.enable)
|
|
||||||
)
|
)
|
||||||
},
|
|
||||||
onClick = {
|
|
||||||
expanded = false
|
|
||||||
onCheckChanged(!module.enabled)
|
|
||||||
}
|
}
|
||||||
)
|
if (module.hasActionScript) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(stringResource(R.string.action)) },
|
||||||
|
onClick = {
|
||||||
|
expanded = false
|
||||||
|
navigator.navigate(ExecuteModuleActionScreenDestination(module.dirId))
|
||||||
|
viewModel.markNeedRefresh()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (module.hasWebUi || module.hasActionScript ) {
|
||||||
|
HorizontalDivider()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!module.remove) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
if (module.enabled) stringResource(R.string.disable)
|
||||||
|
else stringResource(R.string.enable)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
expanded = false
|
||||||
|
onCheckChanged(!module.enabled)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
if (module.remove) {
|
if (module.remove) {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(stringResource(R.string.restore)) },
|
text = { Text(stringResource(R.string.restore)) },
|
||||||
@@ -1112,6 +1125,18 @@ fun ModuleItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun formatSize(size: Long): String {
|
||||||
|
val kb = 1024
|
||||||
|
val mb = kb * 1024
|
||||||
|
val gb = mb * 1024
|
||||||
|
return when {
|
||||||
|
size >= gb -> String.format("%.2f GB", size.toDouble() / gb)
|
||||||
|
size >= mb -> String.format("%.2f MB", size.toDouble() / mb)
|
||||||
|
size >= kb -> String.format("%.2f KB", size.toDouble() / kb)
|
||||||
|
else -> "$size B"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun ModuleItemPreview() {
|
fun ModuleItemPreview() {
|
||||||
@@ -1128,7 +1153,8 @@ fun ModuleItemPreview() {
|
|||||||
updateJson = "",
|
updateJson = "",
|
||||||
hasWebUi = false,
|
hasWebUi = false,
|
||||||
hasActionScript = false,
|
hasActionScript = false,
|
||||||
dirId = "dirId"
|
dirId = "dirId",
|
||||||
|
size = 12345678L
|
||||||
)
|
)
|
||||||
ModuleItem(EmptyDestinationsNavigator, module, "", {}, {}, {}, {}, {})
|
ModuleItem(EmptyDestinationsNavigator, module, "", {}, {}, {}, {}, {})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -621,6 +621,13 @@ fun currentMountSystem(): String {
|
|||||||
return result.substringAfter(":").substringAfter(" ").trim()
|
return result.substringAfter(":").substringAfter(" ").trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getModuleSize(dir: File): Long {
|
||||||
|
val shell = getRootShell()
|
||||||
|
val cmd = "du -sb '${dir.absolutePath}' | awk '{print \$1}'"
|
||||||
|
val result = ShellUtils.fastCmd(shell, cmd).trim()
|
||||||
|
return result.toLongOrNull() ?: 0L
|
||||||
|
}
|
||||||
|
|
||||||
fun setAppProfileTemplate(id: String, template: String): Boolean {
|
fun setAppProfileTemplate(id: String, template: String): Boolean {
|
||||||
val shell = getRootShell()
|
val shell = getRootShell()
|
||||||
val escapedTemplate = template.replace("\"", "\\\"")
|
val escapedTemplate = template.replace("\"", "\\\"")
|
||||||
|
|||||||
@@ -15,11 +15,13 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
|
import java.io.File
|
||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import com.rifsxd.ksunext.ksuApp
|
import com.rifsxd.ksunext.ksuApp
|
||||||
import com.rifsxd.ksunext.ui.util.HanziToPinyin
|
import com.rifsxd.ksunext.ui.util.HanziToPinyin
|
||||||
import com.rifsxd.ksunext.ui.util.listModules
|
import com.rifsxd.ksunext.ui.util.listModules
|
||||||
|
import com.rifsxd.ksunext.ui.util.getModuleSize
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
@@ -43,7 +45,8 @@ class ModuleViewModel : ViewModel() {
|
|||||||
val updateJson: String,
|
val updateJson: String,
|
||||||
val hasWebUi: Boolean,
|
val hasWebUi: Boolean,
|
||||||
val hasActionScript: Boolean,
|
val hasActionScript: Boolean,
|
||||||
val dirId: String
|
val dirId: String,
|
||||||
|
val size: Long
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ModuleUpdateInfo(
|
data class ModuleUpdateInfo(
|
||||||
@@ -117,6 +120,9 @@ class ModuleViewModel : ViewModel() {
|
|||||||
.map { array.getJSONObject(it) }
|
.map { array.getJSONObject(it) }
|
||||||
.map { obj ->
|
.map { obj ->
|
||||||
val id = obj.getString("id")
|
val id = obj.getString("id")
|
||||||
|
val dirId = obj.getString("dir_id")
|
||||||
|
val moduleDir = File("/data/adb/modules/$dirId")
|
||||||
|
val size = getModuleSize(moduleDir)
|
||||||
|
|
||||||
ModuleInfo(
|
ModuleInfo(
|
||||||
id,
|
id,
|
||||||
@@ -131,7 +137,8 @@ class ModuleViewModel : ViewModel() {
|
|||||||
obj.optString("updateJson"),
|
obj.optString("updateJson"),
|
||||||
obj.optBoolean("web"),
|
obj.optBoolean("web"),
|
||||||
obj.optBoolean("action"),
|
obj.optBoolean("action"),
|
||||||
obj.getString("dir_id")
|
dirId,
|
||||||
|
size
|
||||||
)
|
)
|
||||||
}.toList()
|
}.toList()
|
||||||
isNeedRefresh = false
|
isNeedRefresh = false
|
||||||
|
|||||||
Reference in New Issue
Block a user