Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/KrustyCook/KernelSU into HEAD
Browse files Browse the repository at this point in the history
* 'main' of https://github.com/KrustyCook/KernelSU:
  templates/shizuku.root: Fix shizuku service unable to run properly (tiann#2319)
  manager: module: refresh after webui usage (tiann#2317)
  manager: Add sort options on module's appbar (tiann#2308)
  ci: fix ksud release (tiann#2314)
  website: Update Japanese translation of installation guide (tiann#2296)
  Imitate terminal clear command in manager (tiann#2307)
  Minor UI improvements (tiann#2305)

Change-Id: 9a4b59b7bae0d2f47ef66c3e64498ded7f46c90b
Signed-off-by: mrsrimar22 <[email protected]>
  • Loading branch information
mrsrimar22 committed Dec 27, 2024
2 parents 0c89347 + 946391d commit ce5b343
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 89 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ jobs:
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Rename ksud
run: |
mkdir -p ksud
for dir in ./ksud-*; do
if [ -d "$dir" ]; then
echo "----- Rename $dir -----"
ksud_platform_name=$(basename "$dir")
find "$dir" -type f -name "ksud" -path "*/release/*" | while read -r ksud_file; do
if [ -f "$ksud_file" ]; then
mv "$ksud_file" "ksud/$ksud_platform_name"
fi
done
fi
done
- name: Zip AnyKernel3
run: |
for dir in AnyKernel3-*; do
Expand Down Expand Up @@ -79,4 +93,4 @@ jobs:
boot-images-*/Image-*/*.img.gz
kernel-WSA*.zip
kernel-ARCVM*.zip
ksud-*
ksud/ksud-*
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -58,6 +59,9 @@ class MainActivity : ComponentActivity() {

super.onCreate(savedInstanceState)

val isManager = Natives.becomeManager(ksuApp.packageName)
if (isManager) install()

setContent {
KernelSUTheme {
val navController = rememberNavController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import java.util.Locale
@Destination<RootGraph>
fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String) {
var text by rememberSaveable { mutableStateOf("") }
var tempText : String
val logContent = rememberSaveable { StringBuilder() }
val snackBarHost = LocalSnackbarHost.current
val scope = rememberCoroutineScope()
Expand All @@ -63,7 +64,12 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String
runModuleAction(
moduleId = moduleId,
onStdout = {
text += "$it\n"
tempText = "$it\n"
if (tempText.startsWith("")) { // clear command
text = tempText.substring(6)
} else {
text += tempText
}
logContent.append(it).append("\n")
},
onStderr = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ enum class FlashingStatus {
fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) {

var text by rememberSaveable { mutableStateOf("") }
var tempText : String
val logContent = rememberSaveable { StringBuilder() }
var showFloatAction by rememberSaveable { mutableStateOf(false) }

Expand All @@ -107,7 +108,12 @@ fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) {
}
flashing = if (code == 0) FlashingStatus.SUCCESS else FlashingStatus.FAILED
}, onStdout = {
text += "$it\n"
tempText = "$it\n"
if (tempText.startsWith("")) { // clear command
text = tempText.substring(6)
} else {
text += tempText
}
logContent.append(it).append("\n")
}, onStderr = {
logContent.append(it).append("\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
155 changes: 115 additions & 40 deletions manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,22 @@ import androidx.compose.foundation.selection.toggleable
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.filled.MoreVert
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.Checkbox
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarDuration
Expand Down Expand Up @@ -108,9 +115,13 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
val viewModel = viewModel<ModuleViewModel>()
val context = LocalContext.current
val snackBarHost = LocalSnackbarHost.current
val scope = rememberCoroutineScope()
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)

LaunchedEffect(Unit) {
if (viewModel.moduleList.isEmpty() || viewModel.isNeedRefresh) {
viewModel.sortEnabledFirst = prefs.getBoolean("module_sort_enabled_first", false)
viewModel.sortActionFirst = prefs.getBoolean("module_sort_action_first", false)
viewModel.fetchModuleList()
}
}
Expand All @@ -122,9 +133,64 @@ fun ModuleScreen(navigator: DestinationsNavigator) {

val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())

val webUILauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) { viewModel.fetchModuleList() }

Scaffold(
topBar = {
TopAppBar(
actions = {
var showDropdown by remember { mutableStateOf(false) }

IconButton(
onClick = { showDropdown = true },
) {
Icon(
imageVector = Icons.Filled.MoreVert,
contentDescription = stringResource(id = R.string.settings)
)

DropdownMenu(expanded = showDropdown, onDismissRequest = {
showDropdown = false
}) {
DropdownMenuItem(text = {
Text(stringResource(R.string.module_sort_action_first))
}, trailingIcon = {
Checkbox(viewModel.sortActionFirst, null)
}, onClick = {
viewModel.sortActionFirst =
!viewModel.sortActionFirst
prefs.edit()
.putBoolean(
"module_sort_action_first",
viewModel.sortActionFirst
)
.apply()
scope.launch {
viewModel.fetchModuleList()
}
})
DropdownMenuItem(text = {
Text(stringResource(R.string.module_sort_enabled_first))
}, trailingIcon = {
Checkbox(viewModel.sortEnabledFirst, null)
}, onClick = {
viewModel.sortEnabledFirst =
!viewModel.sortEnabledFirst
prefs.edit()
.putBoolean(
"module_sort_enabled_first",
viewModel.sortEnabledFirst
)
.apply()
scope.launch {
viewModel.fetchModuleList()
}
})
}
}
},
scrollBehavior = scrollBehavior,
title = { Text(stringResource(R.string.module)) },
windowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal)
Expand Down Expand Up @@ -191,7 +257,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
},
onClickModule = { id, name, hasWebUi ->
if (hasWebUi) {
context.startActivity(
webUILauncher.launch(
Intent(context, WebUIActivity::class.java)
.setData(Uri.parse("kernelsu://webui/$id"))
.putExtra("id", id)
Expand Down Expand Up @@ -491,14 +557,7 @@ 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)
Expand Down Expand Up @@ -582,23 +641,24 @@ fun ModuleItem(
FilledTonalButton(
modifier = Modifier.defaultMinSize(52.dp, 32.dp),
onClick = {
navigator.navigate(ExecuteModuleActionScreenDestination(module.id))
viewModel.markNeedRefresh()
navigator.navigate(ExecuteModuleActionScreenDestination(module.id))
viewModel.markNeedRefresh()
},
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))
Expand All @@ -611,20 +671,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)
)
}
}

Expand All @@ -637,11 +696,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))
Expand All @@ -653,11 +720,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)
)
}
}
}
}
Expand All @@ -682,4 +757,4 @@ fun ModuleItemPreview() {
hasActionScript = false
)
ModuleItem(EmptyDestinationsNavigator, module, true, "", {}, {}, {}, {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import me.weishu.kernelsu.ui.util.listModules
import me.weishu.kernelsu.ui.util.overlayFsAvailable
import org.json.JSONArray
import org.json.JSONObject
import java.text.Collator
import java.util.Locale

class ModuleViewModel : ViewModel() {

Expand Down Expand Up @@ -52,8 +50,14 @@ class ModuleViewModel : ViewModel() {
var isOverlayAvailable by mutableStateOf(overlayFsAvailable())
private set

var sortEnabledFirst by mutableStateOf(false)
var sortActionFirst by mutableStateOf(false)
val moduleList by derivedStateOf {
val comparator = compareBy(Collator.getInstance(Locale.getDefault()), ModuleInfo::id)
val comparator =
compareBy<ModuleInfo>(
{ if (sortEnabledFirst) !it.enabled else 0 },
{ if (sortActionFirst) !it.hasWebUi && !it.hasActionScript else 0 },
{ it.id })
modules.sortedWith(comparator).also {
isRefreshing = false
}
Expand Down Expand Up @@ -159,4 +163,4 @@ class ModuleViewModel : ViewModel() {

return Triple(zipUrl, version, changelog)
}
}
}
2 changes: 2 additions & 0 deletions manager/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<string name="module_failed_to_disable">无法禁用模块: %s</string>
<string name="module_empty">没有安装模块</string>
<string name="module">模块</string>
<string name="module_sort_action_first">可执行优先</string>
<string name="module_sort_enabled_first">已启用优先</string>
<string name="uninstall">卸载</string>
<string name="module_install">安装</string>
<string name="install">安装</string>
Expand Down
2 changes: 2 additions & 0 deletions manager/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<string name="module_failed_to_disable">Failed to disable module: %s</string>
<string name="module_empty">No module installed</string>
<string name="module">Module</string>
<string name="module_sort_action_first">Sort (Action First)</string>
<string name="module_sort_enabled_first">Sort (Enabled First)</string>
<string name="uninstall">Uninstall</string>
<string name="module_install">Install</string>
<string name="install">Install</string>
Expand Down
Loading

0 comments on commit ce5b343

Please sign in to comment.