fix(modules/bridge/AdditionalBridgeMethodsModule): use Activity to alert instead

This commit is contained in:
PalmDevs 2025-10-15 01:23:57 +07:00
parent 4e33eeaf85
commit 2ca240625d
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -1,5 +1,6 @@
package io.github.revenge.xposed.modules.bridge
import android.app.Activity
import android.app.AlertDialog
import android.content.ClipData
import android.content.ClipboardManager
@ -12,42 +13,6 @@ import java.io.File
class AdditionalBridgeMethodsModule : Module() {
override fun onContext(context: Context) = with(context) {
BridgeModule.registerMethod("revenge.alertError") {
val (error, version) = it
val app = getAppInfo()
val errorString = "$error"
val clipboard = applicationContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Stack Trace", errorString)
AlertDialog.Builder(this)
.setTitle("Revenge Error")
.setMessage(
"""
Revenge: $version
${app.name}: ${app.version} (${app.versionCode})
Device: ${Build.MANUFACTURER} ${Build.MODEL}
""".trimIndent() + errorString
)
.setPositiveButton("OK") { dialog, _ ->
dialog.dismiss()
}
.setNeutralButton("Copy") { dialog, _ ->
clipboard.setPrimaryClip(clip)
Toast.makeText(applicationContext, "Copied stack trace", Toast.LENGTH_SHORT).show()
dialog.dismiss()
}
.show()
null
}
BridgeModule.registerMethod("revenge.showRecoveryAlert") {
Utils.showRecoveryAlert(context)
}
BridgeModule.registerMethod("revenge.fs.getConstants") {
mapOf(
"data" to dataDir.absolutePath,
@ -84,6 +49,44 @@ class AdditionalBridgeMethodsModule : Module() {
}
}
override fun onActivity(activity: Activity) = with(activity) {
BridgeModule.registerMethod("revenge.alertError") {
val (error, version) = it
val app = getAppInfo()
val errorString = "$error"
val clipboard = applicationContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Stack Trace", errorString)
AlertDialog.Builder(this)
.setTitle("Revenge Error")
.setMessage(
"""
Revenge: $version
${app.name}: ${app.version} (${app.versionCode})
Device: ${Build.MANUFACTURER} ${Build.MODEL}
""".trimIndent() + errorString
)
.setPositiveButton("OK") { dialog, _ ->
dialog.dismiss()
}
.setNeutralButton("Copy") { dialog, _ ->
clipboard.setPrimaryClip(clip)
Toast.makeText(applicationContext, "Copied stack trace", Toast.LENGTH_SHORT).show()
dialog.dismiss()
}
.show()
null
}
BridgeModule.registerMethod("revenge.showRecoveryAlert") {
Utils.showRecoveryAlert(this)
}
}
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")