From 4f583a86f2414fa580aa299b3e86ec35bb02b717 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sun, 12 Oct 2025 02:04:09 +0700 Subject: [PATCH] fix(modules): move fs bridge methods to AdditionalBridgeMethodsModule --- .../bridge/AdditionalBridgeMethodsModule.kt | 41 +++++++++++++++++++ .../xposed/modules/bridge/BridgeModule.kt | 25 ----------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/app/src/main/kotlin/io/github/revenge/xposed/modules/bridge/AdditionalBridgeMethodsModule.kt b/app/src/main/kotlin/io/github/revenge/xposed/modules/bridge/AdditionalBridgeMethodsModule.kt index eb252f1..b8ac925 100644 --- a/app/src/main/kotlin/io/github/revenge/xposed/modules/bridge/AdditionalBridgeMethodsModule.kt +++ b/app/src/main/kotlin/io/github/revenge/xposed/modules/bridge/AdditionalBridgeMethodsModule.kt @@ -7,6 +7,7 @@ import android.content.Context import android.os.Build import android.widget.Toast import io.github.revenge.xposed.Module +import java.io.File class AdditionalBridgeMethodsModule : Module() { override fun onContext(context: Context) = with(context) { @@ -41,5 +42,45 @@ class AdditionalBridgeMethodsModule : Module() { null } + + BridgeModule.registerMethod("revenge.fs.getConstants") { + mapOf( + "data" to dataDir.absolutePath, + "files" to filesDir.absolutePath, + "cache" to cacheDir.absolutePath, + ) + } + + BridgeModule.registerMethod("revenge.fs.delete") { + val (path) = it + File(path as String).run { + if (this.isDirectory) this.deleteRecursively() + else this.delete() + } + } + + BridgeModule.registerMethod("revenge.fs.exists") { + val (path) = it + File(path as String).exists() + } + + BridgeModule.registerMethod("revenge.fs.read") { it -> + val (path) = it + val file = File(path as String).apply { openFileGuarded() } + + file.bufferedReader().use { it.readText() } + } + + BridgeModule.registerMethod("revenge.fs.write") { + val (path, contents) = it + val file = File(path as String).apply { openFileGuarded() } + + file.writeText(contents as String) + } + } + + private fun File.openFileGuarded() { + if (!this.exists()) throw Error("Path does not exist: $path") + if (!this.isFile) throw Error("Path is not a file: $path") } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/revenge/xposed/modules/bridge/BridgeModule.kt b/app/src/main/kotlin/io/github/revenge/xposed/modules/bridge/BridgeModule.kt index 854ed08..c8a5392 100644 --- a/app/src/main/kotlin/io/github/revenge/xposed/modules/bridge/BridgeModule.kt +++ b/app/src/main/kotlin/io/github/revenge/xposed/modules/bridge/BridgeModule.kt @@ -5,7 +5,6 @@ import io.github.revenge.xposed.BuildConfig import io.github.revenge.xposed.Constants import io.github.revenge.xposed.Module import io.github.revenge.xposed.Utils.Log -import java.io.File import java.lang.reflect.Method /** @@ -56,11 +55,6 @@ class BridgeModule : Module() { private const val METHOD_NAME_KEY = "method" private const val METHOD_ARGS_KEY = "args" - private fun File.openFileGuarded() { - if (!this.exists()) throw Error("Path does not exist: $path") - if (!this.isFile) throw Error("Path is not a file: $path") - } - private val methods: MutableMap = mutableMapOf("revenge.info" to { mapOf( "name" to Constants.LOADER_NAME, "version" to BuildConfig.VERSION_CODE @@ -74,25 +68,6 @@ class BridgeModule : Module() { "boolean" to false, "args" to it, ) - }, "revenge.fs.delete" to { - val (path) = it - File(path as String).run { - if (this.isDirectory) this.deleteRecursively() - else this.delete() - } - }, "revenge.fs.exists" to { - val (path) = it - File(path as String).exists() - }, "revenge.fs.read" to { it -> - val (path) = it - val file = File(path as String).apply { openFileGuarded() } - - file.bufferedReader().use { it.readText() } - }, "revenge.fs.write" to { it -> - val (path, contents) = it - val file = File(path as String).apply { openFileGuarded() } - - file.writeText(contents as String) }) /**