Step 4-1: Fixed incorrect homepage indexing after enabling KPM
- Adjusted the position of the personalized menu
This commit is contained in:
@@ -25,13 +25,9 @@ import androidx.compose.runtime.DisposableEffect
|
|||||||
import androidx.compose.runtime.compositionLocalOf
|
import androidx.compose.runtime.compositionLocalOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.produceState
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import com.sukisu.ultra.ui.util.getKpmVersion
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.navigation.NavBackStackEntry
|
import androidx.navigation.NavBackStackEntry
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
@@ -55,6 +51,7 @@ import com.sukisu.ultra.ui.screen.SettingPager
|
|||||||
import com.sukisu.ultra.ui.screen.SuperUserPager
|
import com.sukisu.ultra.ui.screen.SuperUserPager
|
||||||
import com.sukisu.ultra.ui.theme.KernelSUTheme
|
import com.sukisu.ultra.ui.theme.KernelSUTheme
|
||||||
import com.sukisu.ultra.ui.util.install
|
import com.sukisu.ultra.ui.util.install
|
||||||
|
import com.sukisu.ultra.ui.util.rememberKpmAvailable
|
||||||
import top.yukonga.miuix.kmp.basic.Scaffold
|
import top.yukonga.miuix.kmp.basic.Scaffold
|
||||||
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||||
|
|
||||||
@@ -149,18 +146,7 @@ fun MainScreen(navController: DestinationsNavigator) {
|
|||||||
val activity = LocalActivity.current
|
val activity = LocalActivity.current
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
// 检查 KPM 版本是否可用
|
val isKpmAvailable = rememberKpmAvailable()
|
||||||
val kpmVersion by produceState(initialValue = "") {
|
|
||||||
value = withContext(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
getKpmVersion()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val isKpmAvailable = kpmVersion.isNotEmpty() && !kpmVersion.contains("Error", ignoreCase = true)
|
|
||||||
val pageCount = if (isKpmAvailable) 5 else 4
|
val pageCount = if (isKpmAvailable) 5 else 4
|
||||||
|
|
||||||
val pagerState = rememberPagerState(initialPage = 0, pageCount = { pageCount })
|
val pagerState = rememberPagerState(initialPage = 0, pageCount = { pageCount })
|
||||||
|
|||||||
@@ -149,6 +149,8 @@ fun HomePager(
|
|||||||
if (kernelVersion.isGKI()) Natives.isLkmMode else null
|
if (kernelVersion.isGKI()) Natives.isLkmMode else null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isKpmAvailable = rememberKpmAvailable()
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(vertical = 12.dp),
|
modifier = Modifier.padding(vertical = 12.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
@@ -175,12 +177,12 @@ fun HomePager(
|
|||||||
},
|
},
|
||||||
onClickSuperuser = {
|
onClickSuperuser = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
pagerState.animateScrollToPage(1)
|
pagerState.animateScrollToPage(getSuperuserPageIndex(isKpmAvailable))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onclickModule = {
|
onclickModule = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
pagerState.animateScrollToPage(2)
|
pagerState.animateScrollToPage(getModulePageIndex(isKpmAvailable))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -709,3 +711,11 @@ fun getManagerVersion(context: Context): Pair<String, Long> {
|
|||||||
val versionCode = PackageInfoCompat.getLongVersionCode(packageInfo)
|
val versionCode = PackageInfoCompat.getLongVersionCode(packageInfo)
|
||||||
return Pair(packageInfo.versionName!!, versionCode)
|
return Pair(packageInfo.versionName!!, versionCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSuperuserPageIndex(isKpmAvailable: Boolean): Int {
|
||||||
|
return if (isKpmAvailable) 2 else 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getModulePageIndex(isKpmAvailable: Boolean): Int {
|
||||||
|
return if (isKpmAvailable) 3 else 2
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.sukisu.ultra.ui.screen
|
package com.sukisu.ultra.ui.screen
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
|
|||||||
@@ -163,31 +163,6 @@ fun SettingPager(
|
|||||||
mutableStateOf(prefs.getBoolean("check_update", true))
|
mutableStateOf(prefs.getBoolean("check_update", true))
|
||||||
}
|
}
|
||||||
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(top = 12.dp)
|
|
||||||
.fillMaxWidth(),
|
|
||||||
) {
|
|
||||||
val personalization = stringResource(id = R.string.personalization)
|
|
||||||
SuperArrow(
|
|
||||||
title = personalization,
|
|
||||||
summary = stringResource(id = R.string.personalization_summary),
|
|
||||||
leftAction = {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.Palette,
|
|
||||||
modifier = Modifier.padding(end = 16.dp),
|
|
||||||
contentDescription = personalization,
|
|
||||||
tint = colorScheme.onBackground
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onClick = {
|
|
||||||
navigator.navigate(PersonalizationDestination) {
|
|
||||||
launchSingleTop = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(top = 12.dp)
|
.padding(top = 12.dp)
|
||||||
@@ -238,6 +213,31 @@ fun SettingPager(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(top = 12.dp)
|
||||||
|
.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
val personalization = stringResource(id = R.string.personalization)
|
||||||
|
SuperArrow(
|
||||||
|
title = personalization,
|
||||||
|
summary = stringResource(id = R.string.personalization_summary),
|
||||||
|
leftAction = {
|
||||||
|
Icon(
|
||||||
|
Icons.Rounded.Palette,
|
||||||
|
modifier = Modifier.padding(end = 16.dp),
|
||||||
|
contentDescription = personalization,
|
||||||
|
tint = colorScheme.onBackground
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
navigator.navigate(PersonalizationDestination) {
|
||||||
|
launchSingleTop = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
KsuIsValid {
|
KsuIsValid {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -266,7 +266,6 @@ fun SettingPager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
KsuIsValid {
|
KsuIsValid {
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(top = 12.dp)
|
.padding(top = 12.dp)
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import android.os.SystemClock
|
|||||||
import android.provider.OpenableColumns
|
import android.provider.OpenableColumns
|
||||||
import android.system.Os
|
import android.system.Os
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.produceState
|
||||||
import com.topjohnwu.superuser.CallbackList
|
import com.topjohnwu.superuser.CallbackList
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import com.topjohnwu.superuser.ShellUtils
|
import com.topjohnwu.superuser.ShellUtils
|
||||||
@@ -720,3 +723,18 @@ fun applyUmountConfigToKernel(): Boolean {
|
|||||||
Log.i(TAG, "apply umount config to kernel result: $result")
|
Log.i(TAG, "apply umount config to kernel result: $result")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查 KPM 版本是否可用
|
||||||
|
@Composable
|
||||||
|
fun rememberKpmAvailable(): Boolean {
|
||||||
|
val kpmVersion by produceState(initialValue = "") {
|
||||||
|
value = withContext(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
getKpmVersion()
|
||||||
|
} catch (_: Exception) {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return kpmVersion.isNotEmpty() && !kpmVersion.contains("Error", ignoreCase = true)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user