From 6bbe40dfdaec27ce7c6b019c6a7604eb60e68122 Mon Sep 17 00:00:00 2001 From: Rifat Azad Date: Wed, 8 Jan 2025 11:13:29 +0600 Subject: [PATCH] manager: improved module mount system & fixed bug for module installation file name error --- .../java/com/rifsxd/ksunext/ui/screen/Home.kt | 6 +++-- .../com/rifsxd/ksunext/ui/screen/Module.kt | 12 +++++----- .../com/rifsxd/ksunext/ui/screen/Settings.kt | 24 +++++++++++-------- .../java/com/rifsxd/ksunext/ui/util/KsuCli.kt | 24 ++++++++++++------- .../app/src/main/res/values-in/strings.xml | 5 ---- .../src/main/res/values-pt-rBR/strings.xml | 5 ---- .../src/main/res/values-zh-rCN/strings.xml | 5 ---- manager/app/src/main/res/values/strings.xml | 6 ++--- 8 files changed, 42 insertions(+), 45 deletions(-) diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt index 2816a88a..3ce760cc 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt @@ -354,6 +354,10 @@ private fun InfoCard() { mutableStateOf(prefs.getBoolean("use_overlay_fs", false)) } + LaunchedEffect(Unit) { + useOverlayFs = prefs.getBoolean("use_overlay_fs", false) + } + ElevatedCard { Column( modifier = Modifier @@ -429,10 +433,8 @@ private fun InfoCard() { InfoCardItem( label = stringResource(R.string.home_module_mount), content = if (useOverlayFs) { - // Show different content if OverlayFS is enabled stringResource(R.string.home_overlayfs_mount) } else { - // Default content when OverlayFS is not enabled stringResource(R.string.home_magic_mount) }, icon = Icons.Filled.SettingsSuggest, diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt index 80a79a92..b8d50d51 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt @@ -96,6 +96,7 @@ import com.rifsxd.ksunext.R import com.rifsxd.ksunext.ui.component.ConfirmResult import com.rifsxd.ksunext.ui.component.rememberConfirmDialog import com.rifsxd.ksunext.ui.component.rememberLoadingDialog +import com.rifsxd.ksunext.ui.util.* import com.rifsxd.ksunext.ui.util.DownloadListener import com.rifsxd.ksunext.ui.util.LocalSnackbarHost import com.rifsxd.ksunext.ui.util.download @@ -240,8 +241,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) { ) { innerPadding -> // confirmation dialog if (showConfirmDialog && zipUri != null) { - // extract the module name from the zipUri - val moduleName = zipUri?.lastPathSegment?.substringAfterLast('/') ?: "Unknown Module" + val moduleName = getFileName(context, zipUri!!) AlertDialog( onDismissRequest = { showConfirmDialog = false }, @@ -251,7 +251,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) { navigator.navigate(FlashScreenDestination(FlashIt.FlashModule(zipUri!!))) viewModel.markNeedRefresh() - }) { Text(stringResource(R.string.confirm)) } @@ -261,15 +260,16 @@ fun ModuleScreen(navigator: DestinationsNavigator) { Text(stringResource(android.R.string.cancel)) } }, - title = { Text(stringResource(R.string.confirm_module_installation)) }, - text = { + title = { Text(stringResource(R.string.module)) }, + text = { Text( stringResource(R.string.module_install_prompt_with_name, moduleName) - ) + ) } ) } + when { hasMagisk -> { Box( diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Settings.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Settings.kt index ef426a05..427607b5 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Settings.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Settings.kt @@ -70,6 +70,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import com.rifsxd.ksunext.BuildConfig import com.rifsxd.ksunext.Natives +import com.rifsxd.ksunext.ksuApp import com.rifsxd.ksunext.R import com.rifsxd.ksunext.ui.component.AboutDialog import com.rifsxd.ksunext.ui.component.ConfirmResult @@ -168,7 +169,9 @@ fun SettingScreen(navigator: DestinationsNavigator) { ) } - var showRestartDialog by remember { mutableStateOf(false) } + val isManager = Natives.becomeManager(ksuApp.packageName) + + var showRebootDialog by remember { mutableStateOf(false) } SwitchItem( icon = Icons.Filled.Build, @@ -178,24 +181,25 @@ fun SettingScreen(navigator: DestinationsNavigator) { ) { prefs.edit().putBoolean("use_overlay_fs", it).apply() useOverlayFs = it - showRestartDialog = true + if (isManager) install() + showRebootDialog = true } - if (showRestartDialog) { + if (showRebootDialog) { AlertDialog( - onDismissRequest = { showRestartDialog = false }, - title = { Text(stringResource(R.string.restart_required)) }, - text = { Text(stringResource(R.string.restart_message)) }, + onDismissRequest = { showRebootDialog = false }, + title = { Text(stringResource(R.string.reboot_required)) }, + text = { Text(stringResource(R.string.reboot_message)) }, confirmButton = { TextButton(onClick = { - showRestartDialog = false - restartKsuNext(context) + showRebootDialog = false + reboot() }) { - Text(stringResource(R.string.restart_now)) + Text(stringResource(R.string.reboot)) } }, dismissButton = { - TextButton(onClick = { showRestartDialog = false }) { + TextButton(onClick = { showRebootDialog = false }) { Text(stringResource(R.string.later)) } } diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/util/KsuCli.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/util/KsuCli.kt index 627d9285..39016566 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/util/KsuCli.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/util/KsuCli.kt @@ -427,6 +427,21 @@ fun getAppProfileTemplate(id: String): String { .to(ArrayList(), null).exec().out.joinToString("\n") } +fun getFileName(context: Context, uri: Uri): String { + var name = "Unknown Module" + if (uri.scheme == ContentResolver.SCHEME_CONTENT) { + val cursor: Cursor? = context.contentResolver.query(uri, null, null, null, null) + cursor?.use { + if (it.moveToFirst()) { + name = it.getString(it.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) + } + } + } else if (uri.scheme == "file") { + name = uri.lastPathSegment ?: "Unknown Module" + } + return name +} + fun setAppProfileTemplate(id: String, template: String): Boolean { val shell = getRootShell() val escapedTemplate = template.replace("\"", "\\\"") @@ -460,11 +475,4 @@ fun launchApp(packageName: String) { fun restartApp(packageName: String) { forceStopApp(packageName) launchApp(packageName) -} - -fun restartKsuNext(context: Context) { - val intent = context.packageManager.getLaunchIntentForPackage(context.packageName) - intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(intent) - Runtime.getRuntime().exit(0) -} +} \ No newline at end of file diff --git a/manager/app/src/main/res/values-in/strings.xml b/manager/app/src/main/res/values-in/strings.xml index 7438a464..da67f719 100644 --- a/manager/app/src/main/res/values-in/strings.xml +++ b/manager/app/src/main/res/values-in/strings.xml @@ -31,7 +31,6 @@ Gagal menonaktifkan modul: %s Tidak ada modul Modul - Yakin instal Anda ingin melanjutkan pemasangan modul %1$s? Menyortir (A - Z) Menyortir (Z - A) @@ -68,10 +67,6 @@ OverlayFS Use OverlayFS Toggle between using OverlayFS or Magic for KernelSU Next\'s mount system. - Restart Required - Changes will take effect after restarting the app. Would you like to restart now? - Restart Now - Later 🔥 Pembangunan Next https://github.com/rifsxd/KernelSU-Next Next cabang eksperimental. Lihat di GitHub! diff --git a/manager/app/src/main/res/values-pt-rBR/strings.xml b/manager/app/src/main/res/values-pt-rBR/strings.xml index d326b716..be30dea7 100644 --- a/manager/app/src/main/res/values-pt-rBR/strings.xml +++ b/manager/app/src/main/res/values-pt-rBR/strings.xml @@ -31,7 +31,6 @@ Falha ao desativar o módulo %s Nenhum módulo instalado Módulo - Confirmação de instalação Deseja continuar instalando o módulo %1$s? Ordenar (A-Z) Ordenar (Z-A) @@ -68,10 +67,6 @@ OverlayFS Use OverlayFS Toggle between using OverlayFS or Magic for KernelSU Next\'s mount system. - Restart Required - Changes will take effect after restarting the app. Would you like to restart now? - Restart Now - Later 🔥 Compilação next https://github.com/rifsxd/KernelSU-Next Branch next experimental. Confira no GitHub! diff --git a/manager/app/src/main/res/values-zh-rCN/strings.xml b/manager/app/src/main/res/values-zh-rCN/strings.xml index 39f2ec48..382c7d31 100644 --- a/manager/app/src/main/res/values-zh-rCN/strings.xml +++ b/manager/app/src/main/res/values-zh-rCN/strings.xml @@ -31,7 +31,6 @@ 无法禁用模块: %s 没有安装模块 模块 - 确认安装 是否要继续安装模块 %1$s ? 种类 (A - Z) 种类 (Z - A) @@ -67,10 +66,6 @@ OverlayFS Use OverlayFS Toggle between using OverlayFS or Magic for KernelSU Next\'s mount system. - Restart Required - Changes will take effect after restarting the app. Would you like to restart now? - Restart Now - Later 因与 Magisk 有冲突,所有模块不可用! 🔥 Next 构建 https://github.com/rifsxd/KernelSU-Next diff --git a/manager/app/src/main/res/values/strings.xml b/manager/app/src/main/res/values/strings.xml index b99841ff..a85cc756 100644 --- a/manager/app/src/main/res/values/strings.xml +++ b/manager/app/src/main/res/values/strings.xml @@ -31,7 +31,6 @@ Failed to disable module: %s No module installed Module - Install confirmation Do you want to continue installing module %1$s? Sort (A-Z) Sort (Z-A) @@ -68,9 +67,8 @@ OverlayFS Use OverlayFS Toggle between using OverlayFS or Magic for KernelSU Next\'s mount system. - Restart Required - Changes will take effect after restarting the app. Would you like to restart now? - Restart Now + Reboot Required + Changes will take effect after rebooting the system. Would you like to reboot now? Later 🔥 Next build https://github.com/rifsxd/KernelSU-Next