forked from tiann/KernelSU
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/tiann/KernelSU
* 'main' of https://github.com/tiann/KernelSU: build(deps): bump the crates group across 1 directory with 38 updates (tiann#2163) build(deps): bump the npm group across 1 directory with 35 updates (tiann#2161) Translations update from Hosted Weblate (tiann#2065) Renewed rmx3511 kernel source git repo link (tiann#2164) manager: Add action.sh for user to manually trigger modules' functionality from manager (tiann#2156) manager: Bump dependencies, Adjust pull refresh UI, Add transitions back (tiann#2139) manager: detect init_boot with Android version in uname (tiann#2142) add device to unofficial supported list (tiann#2136) Signed-off-by: Edwiin Kusuma Jaya <kutemeikito0905@gmail.com>
- Loading branch information
Showing
30 changed files
with
980 additions
and
678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package me.weishu.kernelsu.ui.screen | ||
|
||
import android.os.Environment | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
import androidx.compose.material.icons.filled.Save | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.SnackbarHost | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.key.Key | ||
import androidx.compose.ui.input.key.key | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.unit.dp | ||
import com.ramcosta.composedestinations.annotation.Destination | ||
import com.ramcosta.composedestinations.annotation.RootGraph | ||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
import me.weishu.kernelsu.R | ||
import me.weishu.kernelsu.ui.component.KeyEventBlocker | ||
import me.weishu.kernelsu.ui.util.LocalSnackbarHost | ||
import me.weishu.kernelsu.ui.util.runModuleAction | ||
import java.io.File | ||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import java.util.Locale | ||
|
||
@Composable | ||
@Destination<RootGraph> | ||
fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String) { | ||
var text by rememberSaveable { mutableStateOf("") } | ||
val logContent = rememberSaveable { StringBuilder() } | ||
val snackBarHost = LocalSnackbarHost.current | ||
val scope = rememberCoroutineScope() | ||
val scrollState = rememberScrollState() | ||
var actionResult: Boolean | ||
|
||
LaunchedEffect(Unit) { | ||
if (text.isNotEmpty()) { | ||
return@LaunchedEffect | ||
} | ||
withContext(Dispatchers.IO) { | ||
runModuleAction( | ||
moduleId = moduleId, | ||
onStdout = { | ||
text += "$it\n" | ||
logContent.append(it).append("\n") | ||
}, | ||
onStderr = { | ||
logContent.append(it).append("\n") | ||
} | ||
).let { | ||
actionResult = it | ||
} | ||
} | ||
if (actionResult) navigator.popBackStack() | ||
} | ||
|
||
Scaffold( | ||
topBar = { | ||
TopBar( | ||
onBack = { | ||
navigator.popBackStack() | ||
}, | ||
onSave = { | ||
scope.launch { | ||
val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault()) | ||
val date = format.format(Date()) | ||
val file = File( | ||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), | ||
"KernelSU_module_action_log_${date}.log" | ||
) | ||
file.writeText(logContent.toString()) | ||
snackBarHost.showSnackbar("Log saved to ${file.absolutePath}") | ||
} | ||
} | ||
) | ||
}, | ||
snackbarHost = { SnackbarHost(snackBarHost) } | ||
) { innerPadding -> | ||
KeyEventBlocker { | ||
it.key == Key.VolumeDown || it.key == Key.VolumeUp | ||
} | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize(1f) | ||
.padding(innerPadding) | ||
.verticalScroll(scrollState), | ||
) { | ||
LaunchedEffect(text) { | ||
scrollState.animateScrollTo(scrollState.maxValue) | ||
} | ||
Text( | ||
modifier = Modifier.padding(8.dp), | ||
text = text, | ||
fontSize = MaterialTheme.typography.bodySmall.fontSize, | ||
fontFamily = FontFamily.Monospace, | ||
lineHeight = MaterialTheme.typography.bodySmall.lineHeight, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
private fun TopBar(onBack: () -> Unit = {}, onSave: () -> Unit = {}) { | ||
TopAppBar( | ||
title = { Text(stringResource(R.string.action)) }, | ||
navigationIcon = { | ||
IconButton( | ||
onClick = onBack | ||
) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null) } | ||
}, | ||
actions = { | ||
IconButton(onClick = onSave) { | ||
Icon( | ||
imageVector = Icons.Filled.Save, | ||
contentDescription = stringResource(id = R.string.save_log), | ||
) | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.