From af328f22efeb5aa4d39a2b692aa286b6836b5bb2 Mon Sep 17 00:00:00 2001 From: silvzr <117378129+silvzr@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:59:09 +0100 Subject: [PATCH 1/3] manager: Improve module buttons coexistence ...by using icons instead of text, leaving more space and proper padding. --- .../me/weishu/kernelsu/ui/screen/Module.kt | 78 ++++++++++++------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt index 193f76b21c46..93d5ec69e7f0 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt @@ -33,6 +33,8 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.outlined.Wysiwyg import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.outlined.PlayArrow +import androidx.compose.material.icons.outlined.Download +import androidx.compose.material.icons.outlined.Delete import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ElevatedCard @@ -588,17 +590,18 @@ fun ModuleItem( contentPadding = ButtonDefaults.TextButtonContentPadding ) { Icon( - modifier = Modifier - .padding(end = 7.dp) - .size(20.dp), + modifier = Modifier.size(20.dp), imageVector = Icons.Outlined.PlayArrow, contentDescription = null ) - Text( - text = stringResource(R.string.action), - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize - ) + if (!module.hasWebUi && updateUrl.isEmpty()) { + Text( + modifier = Modifier.padding(start = 7.dp), + text = stringResource(R.string.action), + fontFamily = MaterialTheme.typography.labelMedium.fontFamily, + fontSize = MaterialTheme.typography.labelMedium.fontSize + ) + } } Spacer(modifier = Modifier.weight(0.1f, true)) @@ -611,20 +614,19 @@ fun ModuleItem( interactionSource = interactionSource, contentPadding = ButtonDefaults.TextButtonContentPadding ) { - if (!module.hasActionScript) { - Icon( - modifier = Modifier - .padding(end = 7.dp) - .size(20.dp), - imageVector = Icons.AutoMirrored.Outlined.Wysiwyg, - contentDescription = null + Icon( + modifier = Modifier.size(20.dp), + imageVector = Icons.AutoMirrored.Outlined.Wysiwyg, + contentDescription = null + ) + if (!module.hasActionScript && updateUrl.isEmpty()) { + Text( + modifier = Modifier.padding(start = 7.dp), + fontFamily = MaterialTheme.typography.labelMedium.fontFamily, + fontSize = MaterialTheme.typography.labelMedium.fontSize, + text = stringResource(R.string.open) ) } - Text( - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize, - text = stringResource(R.string.open) - ) } } @@ -637,11 +639,19 @@ fun ModuleItem( shape = ButtonDefaults.textShape, contentPadding = ButtonDefaults.TextButtonContentPadding ) { - Text( - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize, - text = stringResource(R.string.module_update) - ) + Icon( + modifier = Modifier.size(20.dp), + imageVector = Icons.Outlined.Download, + contentDescription = null + ) + if (!module.hasActionScript || !module.hasWebUi) { + Text( + modifier = Modifier.padding(start = 7.dp), + fontFamily = MaterialTheme.typography.labelMedium.fontFamily, + fontSize = MaterialTheme.typography.labelMedium.fontSize, + text = stringResource(R.string.module_update) + ) + } } Spacer(modifier = Modifier.weight(0.1f, true)) @@ -653,11 +663,19 @@ fun ModuleItem( onClick = { onUninstall(module) }, contentPadding = ButtonDefaults.TextButtonContentPadding ) { - Text( - fontFamily = MaterialTheme.typography.labelMedium.fontFamily, - fontSize = MaterialTheme.typography.labelMedium.fontSize, - text = stringResource(R.string.uninstall) - ) + Icon( + modifier = Modifier.size(20.dp), + imageVector = Icons.Outlined.Delete, + contentDescription = null + ) + if (!module.hasActionScript && !module.hasWebUi && updateUrl.isEmpty()) { + Text( + modifier = Modifier.padding(start = 7.dp), + fontFamily = MaterialTheme.typography.labelMedium.fontFamily, + fontSize = MaterialTheme.typography.labelMedium.fontSize, + text = stringResource(R.string.uninstall) + ) + } } } } From 752aca472991b7cd76da841499179bc91fb2ecd3 Mon Sep 17 00:00:00 2001 From: silvzr <117378129+silvzr@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:02:07 +0100 Subject: [PATCH 2/3] manager: Remove module card toggleable behavior without WebUI Co-Authored-By: changhuapeng <9205678+changhuapeng@users.noreply.github.com> --- .../main/java/me/weishu/kernelsu/ui/screen/Module.kt | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt index 93d5ec69e7f0..64001fc7d7e9 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt @@ -493,15 +493,8 @@ fun ModuleItem( onValueChange = { onClick(module) } ) } else { - toggleable( - value = isChecked, - interactionSource = interactionSource, - role = Role.Switch, - indication = indication, - onValueChange = onCheckChanged, - enabled = !module.update - ) - } + this + } } .padding(22.dp, 18.dp, 22.dp, 12.dp) ) { From 244880a4e1192aac0230d57608b777f0afe56326 Mon Sep 17 00:00:00 2001 From: silvzr <117378129+silvzr@users.noreply.github.com> Date: Fri, 20 Dec 2024 21:00:00 +0100 Subject: [PATCH 3/3] manager: Avoid unnecessary function calling in Home.kt the install function is called everytime you go to the HomeScreen, move it to MainActivity instead so it's executed on app launch only. Co-Authored-By: Rifat Azad <33044977+rifsxd@users.noreply.github.com> --- .../app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt | 4 ++++ .../app/src/main/java/me/weishu/kernelsu/ui/screen/Home.kt | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt index 0837597ea945..5737c524a940 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt @@ -45,6 +45,7 @@ import me.weishu.kernelsu.ui.screen.BottomBarDestination import me.weishu.kernelsu.ui.theme.KernelSUTheme import me.weishu.kernelsu.ui.util.LocalSnackbarHost import me.weishu.kernelsu.ui.util.rootAvailable +import me.weishu.kernelsu.ui.util.install class MainActivity : ComponentActivity() { @@ -58,6 +59,9 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) + val isManager = Natives.becomeManager(ksuApp.packageName) + if (isManager) install() + setContent { KernelSUTheme { val navController = rememberNavController() diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Home.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Home.kt index 0fa3b34a8d4e..4631733e8db0 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Home.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Home.kt @@ -73,9 +73,6 @@ fun HomeScreen(navigator: DestinationsNavigator) { verticalArrangement = Arrangement.spacedBy(16.dp) ) { val isManager = Natives.becomeManager(ksuApp.packageName) - SideEffect { - if (isManager) install() - } val ksuVersion = if (isManager) Natives.version else null val lkmMode = ksuVersion?.let { if (it >= Natives.MINIMAL_SUPPORTED_KERNEL_LKM && kernelVersion.isGKI()) Natives.isLkmMode else null