Skip to content

Commit

Permalink
feat: Add patch options (ReVanced#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAabedKhan authored Oct 12, 2023
1 parent 2abadc7 commit ac63667
Show file tree
Hide file tree
Showing 31 changed files with 1,859 additions and 367 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// ReVanced
implementation "app.revanced:revanced-patcher:16.0.2"
implementation "app.revanced:revanced-patcher:17.0.0"

// Signing & aligning
implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.json.JSONObject
import java.io.File
import java.io.PrintWriter
import java.io.StringWriter
import java.lang.Error
import java.util.logging.LogRecord
import java.util.logging.Logger

Expand Down Expand Up @@ -55,6 +54,7 @@ class MainActivity : FlutterActivity() {
val outFilePath = call.argument<String>("outFilePath")
val integrationsPath = call.argument<String>("integrationsPath")
val selectedPatches = call.argument<List<String>>("selectedPatches")
val options = call.argument<Map<String, Map<String, Any>>>("options")
val cacheDirPath = call.argument<String>("cacheDirPath")
val keyStoreFilePath = call.argument<String>("keyStoreFilePath")
val keystorePassword = call.argument<String>("keystorePassword")
Expand All @@ -66,6 +66,7 @@ class MainActivity : FlutterActivity() {
outFilePath != null &&
integrationsPath != null &&
selectedPatches != null &&
options != null &&
cacheDirPath != null &&
keyStoreFilePath != null &&
keystorePassword != null
Expand All @@ -79,6 +80,7 @@ class MainActivity : FlutterActivity() {
outFilePath,
integrationsPath,
selectedPatches,
options,
cacheDirPath,
keyStoreFilePath,
keystorePassword
Expand Down Expand Up @@ -127,6 +129,28 @@ class MainActivity : FlutterActivity() {
put(compatiblePackageJson)
}
})
put("options", JSONArray().apply {
it.options.values.forEach { option ->
val optionJson = JSONObject().apply option@{
put("key", option.key)
put("title", option.title)
put("description", option.description)
put("required", option.required)

when (val value = option.value) {
null -> put("value", null)
is Array<*> -> put("value", JSONArray().apply {

value.forEach { put(it) }
})
else -> put("value", option.value)
}

put("optionClassType", option::class.simpleName)
}
put(optionJson)
}
})
}.let(::put)
}
}.toString().let(result::success)
Expand All @@ -145,6 +169,7 @@ class MainActivity : FlutterActivity() {
outFilePath: String,
integrationsPath: String,
selectedPatches: List<String>,
options: Map<String, Map<String, Any>>,
cacheDirPath: String,
keyStoreFilePath: String,
keystorePassword: String
Expand Down Expand Up @@ -182,7 +207,7 @@ class MainActivity : FlutterActivity() {

object : java.util.logging.Handler() {
override fun publish(record: LogRecord) {
if (record.loggerName?.startsWith("app.revanced") != true) return
if (record.loggerName?.startsWith("app.revanced") != true || cancel) return

updateProgress(-1.0, "", record.message)
}
Expand Down Expand Up @@ -215,6 +240,7 @@ class MainActivity : FlutterActivity() {
cacheDir,
Aapt.binary(applicationContext).absolutePath,
cacheDir.path,
true // TODO: Add option to disable this
)
)

Expand All @@ -234,6 +260,10 @@ class MainActivity : FlutterActivity() {
isCompatible || patch.compatiblePackages.isNullOrEmpty()

compatibleOrUniversal && selectedPatches.any { it == patch.name }
}.onEach { patch ->
options[patch.name]?.forEach { (key, value) ->
patch.options[key] = value
}
}

if (cancel) {
Expand Down
6 changes: 1 addition & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ allprojects {
google()
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/revanced/revanced-patcher")
credentials {
username = (project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")) as String
password = (project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")) as String
}
url 'https://jitpack.io'
}
mavenLocal()
}
Expand Down
4 changes: 1 addition & 3 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=a01b6587e15fe7ed120a0ee299c25982a1eee045abd6a9dd5e216b2f628ef9ac
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
36 changes: 31 additions & 5 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"yesButton": "Yes",
"noButton": "No",
"warning": "Warning",
"options": "Options",
"notice": "Notice",
"noShowAgain": "Don't show this again",
"new": "New",
"add": "Add",
"remove": "Remove",
"navigationView": {
"dashboardTab": "Dashboard",
"patcherTab": "Patcher",
Expand Down Expand Up @@ -71,7 +73,8 @@

"armv7WarningDialogText": "Patching on ARMv7 devices is not yet supported and might fail. Proceed anyways?",

"removedPatchesWarningDialogText": "The following patches have been removed since the last time you used them.\n\n{patches}\n\nProceed anyways?"
"removedPatchesWarningDialogText": "The following patches have been removed since the last time you used them.\n\n{patches}\n\nProceed anyways?",
"requiredOptionDialogText" : "Some patch options have to be set."
},
"appSelectorCard": {
"widgetTitle": "Select an application",
Expand Down Expand Up @@ -114,6 +117,8 @@
"viewTitle": "Select patches",
"searchBarHint": "Search patches",
"universalPatches": "Universal patches",
"newPatches": "New patches",
"patches": "Patches",

"doneButton": "Done",

Expand All @@ -126,15 +131,29 @@
"loadPatchesSelection": "Load patches selection",
"noSavedPatches": "No saved patches for the selected app.\nPress Done to save current selection.",
"noPatchesFound": "No patches found for the selected app",
"setRequiredOption": "Some patches require options to be set:\n\n{patches}\n\nPlease set them before continuing.",

"selectAllPatchesWarningContent": "You are about to select all patches, that includes non-suggested patches and can cause unwanted behavior."
},
"patchOptionsView": {
"viewTitle": "Patch options",
"saveOptions": "Save",

"addOptions": "Add options",
"deselectPatch": "Deselect patch",
"tooltip": "More input options",
"selectFilePath": "Select file path",
"selectFolder": "Select folder",
"selectOption": "Select option",

"requiredOption": "This option is required",
"unsupportedOption": "This option is not supported",
"requiredOptionNull": "The following options have to be set:\n\n{options}"
},
"patchItem": {
"unsupportedDialogText": "Selecting this patch may result in patching errors.\n\nApp version: {packageVersion}\nSupported versions:\n{supportedVersions}",
"unsupportedPatchVersion": "Patch is not supported for this app version. Enable the experimental toggle in settings to proceed.",

"newPatchDialogText": "This is a new patch that has been added since the last time you have patched this app.",
"newPatch": "New patch",
"unsupportedRequiredOption": "This patch contains a required option that is not supported by this app",

"patchesChangeWarningDialogText": "It is recommended to use the default selection of patches because changing it may cause unexpected issues.\n\nIf you know what you are doing, you can enable \"Enable changing selection\" in the settings.",
"patchesChangeWarningDialogButton": "Use default selection"
Expand Down Expand Up @@ -239,10 +258,17 @@
"resetStoredPatchesLabel": "Reset patches",
"resetStoredPatchesHint": "Reset the stored patches selection",

"resetStoredOptionsLabel": "Reset options",
"resetStoredOptionsHint": "Reset all patch options",

"resetStoredPatchesDialogTitle": "Reset patches selection?",
"resetStoredPatchesDialogText": "Resetting patches selection will remove all selected patches.",
"resetStoredPatches": "Patches selection has been reset",

"resetStoredOptionsDialogTitle": "Reset options?",
"resetStoredOptionsDialogText": "Resetting options will remove all saved options.",
"resetStoredOptions": "Options have been reset",

"deleteLogsLabel": "Delete logs",
"deleteLogsHint": "Delete collected manager logs",
"deletedLogs": "Logs deleted",
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit ac63667

Please sign in to comment.