Merge pull request #14 from ShirkNeko/dev
Add input dialogs to the KPM module to optimize control logic and dis…
This commit is contained in:
@@ -51,6 +51,7 @@ import androidx.compose.animation.shrinkVertically
|
|||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import shirkneko.zako.sukisu.ui.theme.CardConfig
|
import shirkneko.zako.sukisu.ui.theme.CardConfig
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Destination<RootGraph>(start = true)
|
@Destination<RootGraph>(start = true)
|
||||||
@@ -406,6 +407,8 @@ fun WarningCard(
|
|||||||
}
|
}
|
||||||
@Composable
|
@Composable
|
||||||
fun ContributionCard() {
|
fun ContributionCard() {
|
||||||
|
val uriHandler = LocalUriHandler.current
|
||||||
|
val links = listOf("https://github.com/ShirkNeko", "https://github.com/udochina")
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
colors = getCardColors(MaterialTheme.colorScheme.secondaryContainer),
|
colors = getCardColors(MaterialTheme.colorScheme.secondaryContainer),
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = getCardElevation())
|
elevation = CardDefaults.cardElevation(defaultElevation = getCardElevation())
|
||||||
@@ -413,6 +416,10 @@ fun ContributionCard() {
|
|||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
.clickable {
|
||||||
|
val randomIndex = Random.nextInt(links.size)
|
||||||
|
uriHandler.openUri(links[randomIndex])
|
||||||
|
}
|
||||||
.padding(24.dp),
|
.padding(24.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
@@ -548,19 +555,15 @@ private fun InfoCard() {
|
|||||||
InfoCardItem(stringResource(R.string.home_selinux_status), getSELinuxStatus())
|
InfoCardItem(stringResource(R.string.home_selinux_status), getSELinuxStatus())
|
||||||
|
|
||||||
|
|
||||||
if (!isSimpleMode) {
|
if (!isSimpleMode){
|
||||||
var showKpmVersion by remember { mutableStateOf(true) }
|
Spacer(Modifier.height(16.dp))
|
||||||
LaunchedEffect(Unit) {
|
val kpmVersion = getKpmVersion()
|
||||||
try {
|
val displayVersion = if (kpmVersion.isEmpty() || kpmVersion.startsWith("Error")) {
|
||||||
getKpmVersion()
|
stringResource(R.string.not_supported)
|
||||||
} catch (e: Exception) {
|
} else {
|
||||||
showKpmVersion = false
|
kpmVersion
|
||||||
}
|
|
||||||
}
|
|
||||||
AnimatedVisibility(visible = showKpmVersion) {
|
|
||||||
Spacer(Modifier.height(16.dp))
|
|
||||||
InfoCardItem(stringResource(R.string.home_kpm_version), getKpmVersion())
|
|
||||||
}
|
}
|
||||||
|
InfoCardItem(stringResource(R.string.home_kpm_version), displayVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -276,10 +276,46 @@ private fun KpmModuleItem(
|
|||||||
val viewModel: KpmViewModel = viewModel()
|
val viewModel: KpmViewModel = viewModel()
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val snackBarHost = remember { SnackbarHostState() }
|
val snackBarHost = remember { SnackbarHostState() }
|
||||||
|
|
||||||
val successMessage = stringResource(R.string.kpm_control_success)
|
val successMessage = stringResource(R.string.kpm_control_success)
|
||||||
val failureMessage = stringResource(R.string.kpm_control_failed)
|
val failureMessage = stringResource(R.string.kpm_control_failed)
|
||||||
|
|
||||||
|
if (viewModel.showInputDialog && viewModel.selectedModuleId == module.id) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { viewModel.hideInputDialog() },
|
||||||
|
title = { Text(stringResource(R.string.kpm_control)) },
|
||||||
|
text = {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = viewModel.inputArgs,
|
||||||
|
onValueChange = { viewModel.updateInputArgs(it) },
|
||||||
|
label = { Text(stringResource(R.string.kpm_args)) },
|
||||||
|
placeholder = { Text(module.args) }
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
scope.launch {
|
||||||
|
val result = viewModel.executeControl()
|
||||||
|
val message = when (result) {
|
||||||
|
0 -> successMessage
|
||||||
|
else -> failureMessage
|
||||||
|
}
|
||||||
|
snackBarHost.showSnackbar(message)
|
||||||
|
onControl()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.confirm))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { viewModel.hideInputDialog() }) {
|
||||||
|
Text(stringResource(R.string.cancel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
colors = getCardColors(MaterialTheme.colorScheme.secondaryContainer),
|
colors = getCardColors(MaterialTheme.colorScheme.secondaryContainer),
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = getCardElevation())
|
elevation = CardDefaults.cardElevation(defaultElevation = getCardElevation())
|
||||||
@@ -326,17 +362,7 @@ private fun KpmModuleItem(
|
|||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
FilledTonalButton(
|
FilledTonalButton(
|
||||||
onClick = {
|
onClick = { viewModel.showInputDialog(module.id) },
|
||||||
scope.launch {
|
|
||||||
val result = viewModel.controlModule(module.id, module.args)
|
|
||||||
val message = when (result) {
|
|
||||||
0 -> successMessage
|
|
||||||
else -> failureMessage
|
|
||||||
}
|
|
||||||
snackBarHost.showSnackbar(message)
|
|
||||||
onControl()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enabled = module.hasAction
|
enabled = module.hasAction
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
|
|||||||
@@ -111,6 +111,38 @@ class KpmViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var showInputDialog by mutableStateOf(false)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var selectedModuleId by mutableStateOf<String?>(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var inputArgs by mutableStateOf("")
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun showInputDialog(moduleId: String) {
|
||||||
|
selectedModuleId = moduleId
|
||||||
|
showInputDialog = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hideInputDialog() {
|
||||||
|
showInputDialog = false
|
||||||
|
selectedModuleId = null
|
||||||
|
inputArgs = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateInputArgs(args: String) {
|
||||||
|
inputArgs = args
|
||||||
|
}
|
||||||
|
|
||||||
|
fun executeControl(): Int {
|
||||||
|
val moduleId = selectedModuleId ?: return -1
|
||||||
|
val result = controlKpmModule(moduleId, inputArgs)
|
||||||
|
hideInputDialog()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
fun controlModule(moduleId: String, args: String? = null): Int {
|
fun controlModule(moduleId: String, args: String? = null): Int {
|
||||||
return try {
|
return try {
|
||||||
val result = controlKpmModule(moduleId, args)
|
val result = controlKpmModule(moduleId, args)
|
||||||
|
|||||||
@@ -225,7 +225,6 @@
|
|||||||
<string name="kpm_empty">暂无已安装的内核模块</string>
|
<string name="kpm_empty">暂无已安装的内核模块</string>
|
||||||
<string name="kpm_version">版本</string>
|
<string name="kpm_version">版本</string>
|
||||||
<string name="kpm_author">作者</string>
|
<string name="kpm_author">作者</string>
|
||||||
<string name="kpm_execute">执行</string>
|
|
||||||
<string name="kpm_uninstall">卸载</string>
|
<string name="kpm_uninstall">卸载</string>
|
||||||
<string name="kpm_uninstall_confirm">确定要卸载内核模块 %1$s 吗?</string>
|
<string name="kpm_uninstall_confirm">确定要卸载内核模块 %1$s 吗?</string>
|
||||||
<string name="kpm_uninstall_success">卸载成功</string>
|
<string name="kpm_uninstall_success">卸载成功</string>
|
||||||
@@ -235,9 +234,11 @@
|
|||||||
<string name="kpm_install_success">加载kpm模块成功</string>
|
<string name="kpm_install_success">加载kpm模块成功</string>
|
||||||
<string name="kpm_install_failed">加载kpm模块失败</string>
|
<string name="kpm_install_failed">加载kpm模块失败</string>
|
||||||
<string name="home_kpm_version">KPM 版本</string>
|
<string name="home_kpm_version">KPM 版本</string>
|
||||||
|
<string name="kpm_control">执行</string>
|
||||||
<string name="close_notice">关闭</string>
|
<string name="close_notice">关闭</string>
|
||||||
<string name="kpm_control_success">成功</string>
|
<string name="kpm_control_success">成功</string>
|
||||||
<string name="kpm_control_failed">错误</string>
|
<string name="kpm_control_failed">错误</string>
|
||||||
|
<string name="not_supported">不支持</string>
|
||||||
<string name="kernel_module_notice">以下内核模块功能由KernelPatch开发,经过修改后加入SukiSU Ultra的内核模块功能</string>
|
<string name="kernel_module_notice">以下内核模块功能由KernelPatch开发,经过修改后加入SukiSU Ultra的内核模块功能</string>
|
||||||
<string name="home_ContributionCard_kernelsu">SukiSU Ultra展望</string>
|
<string name="home_ContributionCard_kernelsu">SukiSU Ultra展望</string>
|
||||||
<string name="home_click_to_ContributionCard_kernelsu">SukiSU Ultra未来将会成为一个相对独立的KSU分支,但是依然感谢官方KernelSU和MKSU等做出的贡献</string>
|
<string name="home_click_to_ContributionCard_kernelsu">SukiSU Ultra未来将会成为一个相对独立的KSU分支,但是依然感谢官方KernelSU和MKSU等做出的贡献</string>
|
||||||
|
|||||||
@@ -227,7 +227,6 @@
|
|||||||
<string name="kpm_empty">No installed kernel modules at this time</string>
|
<string name="kpm_empty">No installed kernel modules at this time</string>
|
||||||
<string name="kpm_version">releases</string>
|
<string name="kpm_version">releases</string>
|
||||||
<string name="kpm_author">author</string>
|
<string name="kpm_author">author</string>
|
||||||
<string name="kpm_execute">fulfillment</string>
|
|
||||||
<string name="kpm_uninstall">uninstallation</string>
|
<string name="kpm_uninstall">uninstallation</string>
|
||||||
<string name="kpm_uninstall_confirm">Determine the kernel module to uninstall: %1$s ?</string>
|
<string name="kpm_uninstall_confirm">Determine the kernel module to uninstall: %1$s ?</string>
|
||||||
<string name="kpm_uninstall_success">Uninstalled successfully</string>
|
<string name="kpm_uninstall_success">Uninstalled successfully</string>
|
||||||
@@ -245,4 +244,5 @@
|
|||||||
<string name="kpm_control_success">success</string>
|
<string name="kpm_control_success">success</string>
|
||||||
<string name="kpm_control_failed">failed</string>
|
<string name="kpm_control_failed">failed</string>
|
||||||
<string name="home_click_to_ContributionCard_kernelsu">SukiSU Ultra will be a relatively independent branch of KSU in the future, but thanks to the official KernelSU and MKSU etc. for their contributions!</string>
|
<string name="home_click_to_ContributionCard_kernelsu">SukiSU Ultra will be a relatively independent branch of KSU in the future, but thanks to the official KernelSU and MKSU etc. for their contributions!</string>
|
||||||
|
<string name="not_supported">unsupported</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user