You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
Add Eruda Support for WebUI X (#354)
* manager: Improvements - Bump MMRL version - Improved SwitchItem when it is not enabled - Added option to enable eruda * manager: Use custom user agent for WebUI X
This commit is contained in:
@@ -5,14 +5,18 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
|
|||||||
import androidx.compose.foundation.selection.toggleable
|
import androidx.compose.foundation.selection.toggleable
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.ListItem
|
import androidx.compose.material3.ListItem
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.RadioButton
|
import androidx.compose.material3.RadioButton
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.semantics.Role
|
import androidx.compose.ui.semantics.Role
|
||||||
|
import com.dergoogler.mmrl.ui.component.LabelItem
|
||||||
|
import com.dergoogler.mmrl.ui.component.text.TextRow
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SwitchItem(
|
fun SwitchItem(
|
||||||
@@ -21,9 +25,11 @@ fun SwitchItem(
|
|||||||
summary: String? = null,
|
summary: String? = null,
|
||||||
checked: Boolean,
|
checked: Boolean,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
onCheckedChange: (Boolean) -> Unit
|
beta: Boolean = false,
|
||||||
|
onCheckedChange: (Boolean) -> Unit,
|
||||||
) {
|
) {
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
|
val stateAlpha = remember(checked, enabled) { Modifier.alpha(if (enabled) 1f else 0.5f) }
|
||||||
|
|
||||||
ListItem(
|
ListItem(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -36,10 +42,30 @@ fun SwitchItem(
|
|||||||
onValueChange = onCheckedChange
|
onValueChange = onCheckedChange
|
||||||
),
|
),
|
||||||
headlineContent = {
|
headlineContent = {
|
||||||
Text(title)
|
TextRow(
|
||||||
|
leadingContent = if (beta) {
|
||||||
|
{
|
||||||
|
LabelItem(
|
||||||
|
modifier = Modifier.then(stateAlpha),
|
||||||
|
text = "Beta"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else null
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.then(stateAlpha),
|
||||||
|
text = title,
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
leadingContent = icon?.let {
|
leadingContent = icon?.let {
|
||||||
{ Icon(icon, title) }
|
{
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.then(stateAlpha),
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = title
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
trailingContent = {
|
trailingContent = {
|
||||||
Switch(
|
Switch(
|
||||||
@@ -51,7 +77,10 @@ fun SwitchItem(
|
|||||||
},
|
},
|
||||||
supportingContent = {
|
supportingContent = {
|
||||||
if (summary != null) {
|
if (summary != null) {
|
||||||
Text(summary)
|
Text(
|
||||||
|
modifier = Modifier.then(stateAlpha),
|
||||||
|
text = summary
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -329,6 +329,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
|
|||||||
}
|
}
|
||||||
if (ksuVersion != null) {
|
if (ksuVersion != null) {
|
||||||
SwitchItem(
|
SwitchItem(
|
||||||
|
beta = true,
|
||||||
enabled = Platform.isAlive,
|
enabled = Platform.isAlive,
|
||||||
icon = Icons.Filled.WebAsset,
|
icon = Icons.Filled.WebAsset,
|
||||||
title = stringResource(id = R.string.use_webuix),
|
title = stringResource(id = R.string.use_webuix),
|
||||||
@@ -339,6 +340,24 @@ fun SettingScreen(navigator: DestinationsNavigator) {
|
|||||||
useWebUIX = it
|
useWebUIX = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var useWebUIXEruda by rememberSaveable {
|
||||||
|
mutableStateOf(
|
||||||
|
prefs.getBoolean("use_webuix_eruda", false)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (ksuVersion != null) {
|
||||||
|
SwitchItem(
|
||||||
|
beta = true,
|
||||||
|
enabled = Platform.isAlive && useWebUIX && enableWebDebugging,
|
||||||
|
icon = Icons.Filled.FormatListNumbered,
|
||||||
|
title = stringResource(id = R.string.use_webuix_eruda),
|
||||||
|
summary = stringResource(id = R.string.use_webuix_eruda_summary),
|
||||||
|
checked = useWebUIXEruda
|
||||||
|
) {
|
||||||
|
prefs.edit().putBoolean("use_webuix_eruda", it).apply()
|
||||||
|
useWebUIXEruda = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isOverlayAvailable && useOverlayFs) {
|
if (isOverlayAvailable && useOverlayFs) {
|
||||||
val shrink = stringResource(id = R.string.shrink_sparse_image)
|
val shrink = stringResource(id = R.string.shrink_sparse_image)
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import androidx.core.view.ViewCompat
|
|||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.webkit.WebViewAssetLoader
|
import androidx.webkit.WebViewAssetLoader
|
||||||
|
import com.dergoogler.mmrl.platform.model.ModId
|
||||||
import com.dergoogler.mmrl.webui.interfaces.WXOptions
|
import com.dergoogler.mmrl.webui.interfaces.WXOptions
|
||||||
import com.dergoogler.mmrl.webui.model.ModId
|
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import com.rifsxd.ksunext.ui.util.createRootShell
|
import com.rifsxd.ksunext.ui.util.createRootShell
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.dergoogler.mmrl.platform.Platform
|
import com.dergoogler.mmrl.platform.Platform
|
||||||
|
import com.dergoogler.mmrl.platform.model.ModId
|
||||||
import com.dergoogler.mmrl.ui.component.Loading
|
import com.dergoogler.mmrl.ui.component.Loading
|
||||||
import com.dergoogler.mmrl.webui.interfaces.WXOptions
|
|
||||||
import com.dergoogler.mmrl.webui.model.ModId
|
|
||||||
import com.dergoogler.mmrl.webui.screen.WebUIScreen
|
import com.dergoogler.mmrl.webui.screen.WebUIScreen
|
||||||
import com.dergoogler.mmrl.webui.util.rememberWebUIOptions
|
import com.dergoogler.mmrl.webui.util.rememberWebUIOptions
|
||||||
import com.rifsxd.ksunext.BuildConfig
|
import com.rifsxd.ksunext.BuildConfig
|
||||||
@@ -28,6 +27,24 @@ import kotlinx.coroutines.launch
|
|||||||
class WebUIXActivity : ComponentActivity() {
|
class WebUIXActivity : ComponentActivity() {
|
||||||
private lateinit var webView: WebView
|
private lateinit var webView: WebView
|
||||||
|
|
||||||
|
private val userAgent
|
||||||
|
get(): String {
|
||||||
|
val ksuVersion = BuildConfig.VERSION_CODE
|
||||||
|
|
||||||
|
val platform = Platform.get("Unknown") {
|
||||||
|
platform.name
|
||||||
|
}
|
||||||
|
|
||||||
|
val platformVersion = Platform.get(-1) {
|
||||||
|
moduleManager.versionCode
|
||||||
|
}
|
||||||
|
|
||||||
|
val osVersion = Build.VERSION.RELEASE
|
||||||
|
val deviceModel = Build.MODEL
|
||||||
|
|
||||||
|
return "KernelSU Next/$ksuVersion (Linux; Android $osVersion; $deviceModel; $platform/$platformVersion)"
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
@@ -70,6 +87,7 @@ class WebUIXActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val webDebugging = prefs.getBoolean("enable_web_debugging", false)
|
val webDebugging = prefs.getBoolean("enable_web_debugging", false)
|
||||||
|
val erudaInject = prefs.getBoolean("use_webuix_eruda", false)
|
||||||
val dark = isSystemInDarkTheme()
|
val dark = isSystemInDarkTheme()
|
||||||
|
|
||||||
val options = rememberWebUIOptions(
|
val options = rememberWebUIOptions(
|
||||||
@@ -77,7 +95,9 @@ class WebUIXActivity : ComponentActivity() {
|
|||||||
debug = webDebugging,
|
debug = webDebugging,
|
||||||
appVersionCode = BuildConfig.VERSION_CODE,
|
appVersionCode = BuildConfig.VERSION_CODE,
|
||||||
isDarkMode = dark,
|
isDarkMode = dark,
|
||||||
cls = WebUIXActivity::class.java
|
enableEruda = erudaInject,
|
||||||
|
cls = WebUIXActivity::class.java,
|
||||||
|
userAgentString = userAgent
|
||||||
)
|
)
|
||||||
|
|
||||||
WebUIScreen(
|
WebUIScreen(
|
||||||
|
|||||||
@@ -196,4 +196,6 @@
|
|||||||
<string name="settings_language">Language</string>
|
<string name="settings_language">Language</string>
|
||||||
<string name="use_webuix">Use WebUI X</string>
|
<string name="use_webuix">Use WebUI X</string>
|
||||||
<string name="use_webuix_summary">Use WebUI X instead of WebUI, which supports more APIs.</string>
|
<string name="use_webuix_summary">Use WebUI X instead of WebUI, which supports more APIs.</string>
|
||||||
|
<string name="use_webuix_eruda">Inject Eruda into WebUI X</string>
|
||||||
|
<string name="use_webuix_eruda_summary">Inject a debug console into WebUI X to make debugging easier. Requires web debugging to be on.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ parcelablelist = "2.0.1"
|
|||||||
libsu = "6.0.0"
|
libsu = "6.0.0"
|
||||||
apksign = "1.4"
|
apksign = "1.4"
|
||||||
cmaker = "1.2"
|
cmaker = "1.2"
|
||||||
mmrl = "b3c7ca55e0"
|
mmrl = "v33560"
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
agp-app = { id = "com.android.application", version.ref = "agp" }
|
agp-app = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
|||||||
Reference in New Issue
Block a user