[manager]: Add KPM function display options and related settings

- Eruda injection web UI X will not be displayed when the modification is not enabled.

Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
ShirkNeko
2025-05-13 21:44:42 +08:00
parent 9e7ea19567
commit 01199470f2
7 changed files with 92 additions and 32 deletions

View File

@@ -1,5 +1,6 @@
package com.sukisu.ultra.ui
import android.content.Context
import android.database.ContentObserver
import android.os.Build
import android.os.Bundle
@@ -13,6 +14,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavHostController
@@ -167,6 +169,10 @@ private fun BottomBar(navController: NavHostController) {
val containerColor = MaterialTheme.colorScheme.surfaceVariant
val cardColor = MaterialTheme.colorScheme.surfaceVariant
// 检查是否显示KPM
val showKpmInfo = LocalContext.current.getSharedPreferences("settings", Context.MODE_PRIVATE)
.getBoolean("show_kpm_info", true)
NavigationBar(
modifier = Modifier.windowInsetsPadding(
WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal)
@@ -179,7 +185,7 @@ private fun BottomBar(navController: NavHostController) {
) {
BottomBarDestination.entries.forEach { destination ->
if (destination == BottomBarDestination.Kpm) {
if (kpmVersion.isNotEmpty() && !kpmVersion.startsWith("Error")) {
if (kpmVersion.isNotEmpty() && !kpmVersion.startsWith("Error") && showKpmInfo) {
if (!fullFeatured && destination.rootRequired) return@forEach
val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction)
NavigationBarItem(

View File

@@ -133,6 +133,7 @@ fun HomeScreen(navigator: DestinationsNavigator) {
var isHideOtherInfo by rememberSaveable { mutableStateOf(false) }
var isHideSusfsStatus by rememberSaveable { mutableStateOf(false) }
var isHideLinkCard by rememberSaveable { mutableStateOf(false) }
var showKpmInfo by rememberSaveable { mutableStateOf(true) }
// 从 SharedPreferences 加载简洁模式状态
LaunchedEffect(Unit) {
@@ -150,6 +151,9 @@ fun HomeScreen(navigator: DestinationsNavigator) {
isHideLinkCard = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
.getBoolean("is_hide_link_card", false)
showKpmInfo = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
.getBoolean("show_kpm_info", true)
}
val kernelVersion = getKernelVersion()
@@ -487,6 +491,9 @@ private fun StatusCard(
val isHideSusfsStatus = LocalContext.current.getSharedPreferences("settings", Context.MODE_PRIVATE)
.getBoolean("is_hide_susfs_status", false)
val showKpmInfo = LocalContext.current.getSharedPreferences("settings", Context.MODE_PRIVATE)
.getBoolean("show_kpm_info", true)
Icon(
Icons.Outlined.CheckCircle,
contentDescription = stringResource(R.string.home_working),
@@ -526,7 +533,7 @@ private fun StatusCard(
)
val kpmVersion = getKpmVersion()
if (kpmVersion.isNotEmpty() && !kpmVersion.startsWith("Error")) {
if (kpmVersion.isNotEmpty() && !kpmVersion.startsWith("Error") && showKpmInfo) {
Spacer(Modifier.height(4.dp))
Text(
text = stringResource(R.string.home_kpm_module, getKpmModuleCount()),
@@ -790,6 +797,8 @@ private fun InfoCard() {
val context = LocalContext.current
val isSimpleMode = LocalContext.current.getSharedPreferences("settings", Context.MODE_PRIVATE)
.getBoolean("is_simple_mode", false)
val showKpmInfo = LocalContext.current.getSharedPreferences("settings", Context.MODE_PRIVATE)
.getBoolean("show_kpm_info", true)
ElevatedCard(
colors = getCardColors(MaterialTheme.colorScheme.surfaceContainerHighest),
@@ -891,22 +900,25 @@ private fun InfoCard() {
val kpmVersion = getKpmVersion()
val isKpmConfigured = checkKpmConfigured()
val displayVersion = if (kpmVersion.isEmpty() || kpmVersion.startsWith("Error")) {
val statusText = if (isKpmConfigured) {
stringResource(R.string.kernel_patched)
// 根据showKpmInfo决定是否显示KPM信息
if (showKpmInfo) {
val displayVersion = if (kpmVersion.isEmpty() || kpmVersion.startsWith("Error")) {
val statusText = if (isKpmConfigured) {
stringResource(R.string.kernel_patched)
} else {
stringResource(R.string.kernel_not_enabled)
}
"${stringResource(R.string.not_supported)} ($statusText)"
} else {
stringResource(R.string.kernel_not_enabled)
"${stringResource(R.string.supported)} ($kpmVersion)"
}
"${stringResource(R.string.not_supported)} ($statusText)"
} else {
"${stringResource(R.string.supported)} ($kpmVersion)"
}
InfoCardItem(
stringResource(R.string.home_kpm_version),
displayVersion,
icon = Icons.Default.Code
)
InfoCardItem(
stringResource(R.string.home_kpm_version),
displayVersion,
icon = Icons.Default.Code
)
}
}
}

View File

@@ -176,6 +176,17 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
isHideOtherInfo = newValue
}
// 显示KPM开关状态
var isShowKpmInfo by remember {
mutableStateOf(prefs.getBoolean("show_kpm_info", true))
}
// 更新显示KPM开关状态
val onShowKpmInfoChange = { newValue: Boolean ->
prefs.edit { putBoolean("show_kpm_info", newValue) }
isShowKpmInfo = newValue
}
// 隐藏SuSFS状态开关状态
var isHideSusfsStatus by remember {
mutableStateOf(prefs.getBoolean("is_hide_susfs_status", false))
@@ -642,6 +653,21 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
color = MaterialTheme.colorScheme.outlineVariant
)
// 显示KPM开关
SwitchItem(
icon = Icons.Filled.VisibilityOff,
title = stringResource(R.string.show_kpm_info),
summary = stringResource(R.string.show_kpm_info_summary),
checked = isShowKpmInfo
) {
onShowKpmInfoChange(it)
}
HorizontalDivider(
modifier = Modifier.padding(horizontal = 16.dp),
color = MaterialTheme.colorScheme.outlineVariant
)
// 隐藏链接信息
SwitchItem(
icon = Icons.Filled.VisibilityOff,

View File

@@ -6,6 +6,11 @@ import android.net.Uri
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
@@ -81,7 +86,6 @@ fun SettingScreen(navigator: DestinationsNavigator) {
AboutDialog(it)
}
val loadingDialog = rememberLoadingDialog()
// endregion
Column(
modifier = Modifier
@@ -89,12 +93,8 @@ fun SettingScreen(navigator: DestinationsNavigator) {
.nestedScroll(scrollBehavior.nestedScrollConnection)
.verticalScroll(rememberScrollState())
) {
// region 上下文与协程
val context = LocalContext.current
val scope = rememberCoroutineScope()
// endregion
// region 日志导出功能
val exportBugreportLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.CreateDocument("application/gzip")
) { uri: Uri? ->
@@ -184,7 +184,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
}
}
// 设置分组卡片 - 应用设置
// 应用设置
Card(
modifier = Modifier
.fillMaxWidth()
@@ -240,6 +240,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
)
}
// Web X 开关
var useWebUIX by rememberSaveable {
mutableStateOf(
prefs.getBoolean("use_webuix", false)
@@ -258,22 +259,30 @@ fun SettingScreen(navigator: DestinationsNavigator) {
useWebUIX = it
}
}
// Web X Eruda 开关
var useWebUIXEruda by rememberSaveable {
mutableStateOf(
prefs.getBoolean("use_webuix_eruda", false)
)
}
KsuIsValid {
SwitchItem(
beta = true,
enabled = Platform.isAlive && useWebUIX && enableWebDebugging,
icon = Icons.Filled.FormatListNumbered,
title = stringResource(id = R.string.use_webuix_eruda),
summary = stringResource(id = R.string.use_webuix_eruda_summary),
checked = useWebUIXEruda
AnimatedVisibility(
visible = useWebUIX && enableWebDebugging,
enter = fadeIn() + expandVertically(),
exit = fadeOut() + shrinkVertically()
) {
prefs.edit { putBoolean("use_webuix_eruda", it) }
useWebUIXEruda = it
SwitchItem(
beta = true,
enabled = Platform.isAlive && useWebUIX && enableWebDebugging,
icon = Icons.Filled.FormatListNumbered,
title = stringResource(id = R.string.use_webuix_eruda),
summary = stringResource(id = R.string.use_webuix_eruda_summary),
checked = useWebUIXEruda
) {
prefs.edit { putBoolean("use_webuix_eruda", it) }
useWebUIXEruda = it
}
}
}
@@ -289,7 +298,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
}
}
// 设置分组卡片 - 工具
// 工具
Card(
modifier = Modifier
.fillMaxWidth()

View File

@@ -8,7 +8,6 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf