manager: allow enable webview debugging (#1412)

This commit is contained in:
5ec1cff
2024-03-03 22:24:02 +08:00
committed by GitHub
parent dbe43b1540
commit cd772fa250
4 changed files with 23 additions and 0 deletions

View File

@@ -101,6 +101,21 @@ fun SettingScreen(navigator: DestinationsNavigator) {
checkUpdate = it
}
var enableWebDebugging by rememberSaveable {
mutableStateOf(
prefs.getBoolean("enable_web_debugging", false)
)
}
SwitchItem(
icon = Icons.Filled.Update,
title = stringResource(id = R.string.enable_web_debugging),
summary = stringResource(id = R.string.enable_web_debugging_summary),
checked = enableWebDebugging
) {
prefs.edit().putBoolean("enable_web_debugging", it).apply()
enableWebDebugging = it
}
ListItem(
leadingContent = {

View File

@@ -2,6 +2,8 @@ package me.weishu.kernelsu.ui.screen
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.util.Log
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
@@ -31,6 +33,8 @@ fun WebScreen(navigator: DestinationsNavigator, moduleId: String, moduleName: St
val context = LocalContext.current
DisposableEffect(Unit) {
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
WebView.setWebContentsDebuggingEnabled(prefs.getBoolean("enable_web_debugging", false))
onDispose {
if (WebViewInterface.isHideSystemUI && context is Activity) {
showSystemUI(context.window)

View File

@@ -106,4 +106,6 @@
<string name="settings_check_update_summary">在应用启动后自动检查是否有最新版</string>
<string name="grant_root_failed">获取 root 失败!</string>
<string name="open">打开</string>
<string name="enable_web_debugging">启用 WebView 调试</string>
<string name="enable_web_debugging_summary">可用于调试 WebUI ,请仅在需要时启用。</string>
</resources>

View File

@@ -108,4 +108,6 @@
<string name="settings_check_update_summary">Automatically check for updates when opening the app</string>
<string name="grant_root_failed">Failed to grant root!</string>
<string name="open">Open</string>
<string name="enable_web_debugging">Enable WebView Debugging</string>
<string name="enable_web_debugging_summary">Can be used to debug WebUI, please enable only when needed.</string>
</resources>