From 4b917b21b7121c2fedbe24dbfac5704e2d104f7e Mon Sep 17 00:00:00 2001 From: Sculas Date: Thu, 8 Sep 2022 21:40:59 +0200 Subject: [PATCH] feat: add deprecated & options to patches.json --- README-template.md | 82 +++++++++++++++---- .../app/revanced/meta/json/Generator.kt | 21 ++++- .../app/revanced/meta/json/JsonPatch.kt | 10 +++ 3 files changed, 96 insertions(+), 17 deletions(-) diff --git a/README-template.md b/README-template.md index 40cc7cfa..d6c75707 100644 --- a/README-template.md +++ b/README-template.md @@ -12,16 +12,23 @@ This section explains the JSON format for the [patches.json](patches.json) file. The file contains an array of objects, each object representing a patch. The object contains the following properties: -| key | description | -|-------------------------------|------------------------------------------------------------------------------------------------------------------| -| `name` | The name of the patch. | -| `description` | The description of the patch. | -| `version` | The version of the patch. | -| `excluded` | Whether a patch is excluded by default. If `true`, the patch must never be included by default. | -| `dependencies` | An array of dependencies, which are patch names. | -| `compatiblePackages` | An array of packages compatible with this patch. | -| `compatiblePackages.name` | The name of the package. | -| `compatiblePackages.versions` | An array of versions of the package compatible with this patch. If empty, all versions are seemingly compatible. | +| key | description | +|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `name` | The name of the patch. | +| `description` | The description of the patch. | +| `version` | The version of the patch. | +| `excluded` | Whether the patch is excluded by default. If `true`, the patch must never be included by default. | +| `deprecated` | Whether the patch is deprecated. | +| `options` | An array of options for this patch. | +| `options.key` | The key of the option. | +| `options.title` | The title of the option. | +| `options.description` | The description of the option. | +| `options.required` | Whether the option is required. | +| `options.choices?` | An array of choices of the option. This may be `null` if this option has no choices. The element type of this array may be any type. It can be a `String`, `Int` or something else. | +| `dependencies` | An array of dependencies, which are patch names. | +| `compatiblePackages` | An array of packages compatible with this patch. | +| `compatiblePackages.name` | The name of the package. | +| `compatiblePackages.versions` | An array of versions of the package compatible with this patch. If empty, all versions are seemingly compatible. | Example: @@ -32,6 +39,8 @@ Example: "description": "Adds the ability to remember the video quality you chose in the video quality flyout.", "version": "0.0.1", "excluded": false, + "deprecated": false, + "options": [], "dependencies": [ "integrations", "video-id-hook" @@ -46,24 +55,67 @@ Example: "17.27.39", "17.28.34", "17.29.34", - "17.32.35" + "17.32.35", + "17.33.42" ] } ] }, { - "name": "client-spoof", - "description": "Spoofs the YouTube or Vanced client to prevent playback issues.", + "name": "theme", + "description": "Enables a custom theme.", "version": "0.0.1", "excluded": false, - "dependencies": [], + "deprecated": false, + "options": [ + { + "key": "theme", + "title": "Theme", + "description": "Select a theme.", + "required": true, + "choices": [ + "Amoled" + ] + } + ], + "dependencies": [ + "locale-config-fix" + ], "compatiblePackages": [ { "name": "com.google.android.youtube", "versions": [] + } + ] + }, + { + "name": "custom-branding", + "description": "Changes the YouTube launcher icon and name to your choice (defaults to ReVanced).", + "version": "0.0.1", + "excluded": false, + "deprecated": false, + "options": [ + { + "key": "appName", + "title": "Application Name", + "description": "The name of the application it will show on your home screen.", + "required": true, + "choices": null }, { - "name": "com.vanced.android.youtube", + "key": "appIconPath", + "title": "Application Icon Path", + "description": "A path to the icon of the application.", + "required": false, + "choices": null + } + ], + "dependencies": [ + "locale-config-fix" + ], + "compatiblePackages": [ + { + "name": "com.google.android.youtube", "versions": [] } ] diff --git a/src/main/kotlin/app/revanced/meta/json/Generator.kt b/src/main/kotlin/app/revanced/meta/json/Generator.kt index 3585c3b1..b7a87a43 100644 --- a/src/main/kotlin/app/revanced/meta/json/Generator.kt +++ b/src/main/kotlin/app/revanced/meta/json/Generator.kt @@ -3,14 +3,17 @@ package app.revanced.meta.json import app.revanced.meta.Bundle import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages import app.revanced.patcher.extensions.PatchExtensions.dependencies +import app.revanced.patcher.extensions.PatchExtensions.deprecated import app.revanced.patcher.extensions.PatchExtensions.description import app.revanced.patcher.extensions.PatchExtensions.include +import app.revanced.patcher.extensions.PatchExtensions.options import app.revanced.patcher.extensions.PatchExtensions.patchName import app.revanced.patcher.extensions.PatchExtensions.version -import com.google.gson.Gson +import app.revanced.patcher.patch.PatchOption +import com.google.gson.GsonBuilder import java.io.File -private val gson = Gson() +private val gson = GsonBuilder().serializeNulls().create() fun generateJson(bundle: Bundle) { val patches = bundle.map { @@ -19,6 +22,20 @@ fun generateJson(bundle: Bundle) { it.description ?: "This patch has no description.", it.version ?: "0.0.0", !it.include, + it.deprecated != null, + it.options?.map { option -> + Option( + option.key, + option.title, + option.description, + option.required, + option.let { lo -> + if (lo is PatchOption.ListOption<*>) { + lo.options.toMutableList().toTypedArray() + } else null + } + ) + }?.toTypedArray() ?: emptyArray(), it.dependencies?.map { dep -> dep.java.patchName }?.toTypedArray() ?: emptyArray(), diff --git a/src/main/kotlin/app/revanced/meta/json/JsonPatch.kt b/src/main/kotlin/app/revanced/meta/json/JsonPatch.kt index 04242cff..9099fc31 100644 --- a/src/main/kotlin/app/revanced/meta/json/JsonPatch.kt +++ b/src/main/kotlin/app/revanced/meta/json/JsonPatch.kt @@ -7,6 +7,8 @@ data class JsonPatch( val description: String, val version: String, val excluded: Boolean, + val deprecated: Boolean, + val options: Array