js: add moduleInfo method (#2057)
Add a `ksu.moduleInfo()` in JS. resolves https://github.com/tiann/KernelSU/issues/1571 test module's index.html  The test module: [moduleInfo_test.zip](https://github.com/user-attachments/files/17001977/moduleInfo_test.zip) test module's result: 
This commit is contained in:
@@ -29,7 +29,8 @@ class WebUIActivity : ComponentActivity() {
|
||||
val prefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
WebView.setWebContentsDebuggingEnabled(prefs.getBoolean("enable_web_debugging", false))
|
||||
|
||||
val webRoot = File("/data/adb/modules/${moduleId}/webroot")
|
||||
val moduleDir = "/data/adb/modules/${moduleId}"
|
||||
val webRoot = File("${moduleDir}/webroot")
|
||||
val rootShell = createRootShell(true).also { this.rootShell = it }
|
||||
val webViewAssetLoader = WebViewAssetLoader.Builder()
|
||||
.setDomain("mui.kernelsu.org")
|
||||
@@ -52,7 +53,7 @@ class WebUIActivity : ComponentActivity() {
|
||||
settings.javaScriptEnabled = true
|
||||
settings.domStorageEnabled = true
|
||||
settings.allowFileAccess = false
|
||||
webviewInterface = WebViewInterface(this@WebUIActivity, this)
|
||||
webviewInterface = WebViewInterface(this@WebUIActivity, this, moduleDir)
|
||||
addJavascriptInterface(webviewInterface, "ksu")
|
||||
setWebViewClient(webViewClient)
|
||||
loadUrl("https://mui.kernelsu.org/index.html")
|
||||
|
||||
@@ -14,13 +14,15 @@ import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import com.topjohnwu.superuser.CallbackList
|
||||
import com.topjohnwu.superuser.ShellUtils
|
||||
import me.weishu.kernelsu.ui.util.listModules
|
||||
import me.weishu.kernelsu.ui.util.createRootShell
|
||||
import me.weishu.kernelsu.ui.util.withNewRootShell
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.io.File
|
||||
|
||||
class WebViewInterface(val context: Context, private val webView: WebView) {
|
||||
class WebViewInterface(val context: Context, private val webView: WebView, private val modDir: String) {
|
||||
|
||||
@JavascriptInterface
|
||||
fun exec(cmd: String): String {
|
||||
@@ -170,6 +172,27 @@ class WebViewInterface(val context: Context, private val webView: WebView) {
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun moduleInfo(): String {
|
||||
val moduleInfos = JSONArray(listModules())
|
||||
var currentModuleInfo = JSONObject()
|
||||
currentModuleInfo.put("moduleDir", modDir)
|
||||
val moduleId = File(modDir).getName()
|
||||
for (i in 0 until moduleInfos.length()) {
|
||||
val currentInfo = moduleInfos.getJSONObject(i)
|
||||
|
||||
if (currentInfo.getString("id") != moduleId) {
|
||||
continue
|
||||
}
|
||||
|
||||
var keys = currentInfo.keys()
|
||||
for(key in keys) {
|
||||
currentModuleInfo.put(key, currentInfo.get(key));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return currentModuleInfo.toString();
|
||||
}
|
||||
}
|
||||
|
||||
fun hideSystemUI(window: Window) {
|
||||
|
||||
Reference in New Issue
Block a user