feat: add deprecated & options to patches.json

This commit is contained in:
Sculas 2022-09-08 21:40:59 +02:00
parent ecc9086940
commit 4b917b21b7
3 changed files with 96 additions and 17 deletions

View file

@ -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: The file contains an array of objects, each object representing a patch. The object contains the following properties:
| key | description | | key | description |
|-------------------------------|------------------------------------------------------------------------------------------------------------------| |-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name` | The name of the patch. | | `name` | The name of the patch. |
| `description` | The description of the patch. | | `description` | The description of the patch. |
| `version` | The version 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. | | `excluded` | Whether the patch is excluded by default. If `true`, the patch must never be included by default. |
| `dependencies` | An array of dependencies, which are patch names. | | `deprecated` | Whether the patch is deprecated. |
| `compatiblePackages` | An array of packages compatible with this patch. | | `options` | An array of options for this patch. |
| `compatiblePackages.name` | The name of the package. | | `options.key` | The key of the option. |
| `compatiblePackages.versions` | An array of versions of the package compatible with this patch. If empty, all versions are seemingly compatible. | | `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: Example:
@ -32,6 +39,8 @@ Example:
"description": "Adds the ability to remember the video quality you chose in the video quality flyout.", "description": "Adds the ability to remember the video quality you chose in the video quality flyout.",
"version": "0.0.1", "version": "0.0.1",
"excluded": false, "excluded": false,
"deprecated": false,
"options": [],
"dependencies": [ "dependencies": [
"integrations", "integrations",
"video-id-hook" "video-id-hook"
@ -46,24 +55,67 @@ Example:
"17.27.39", "17.27.39",
"17.28.34", "17.28.34",
"17.29.34", "17.29.34",
"17.32.35" "17.32.35",
"17.33.42"
] ]
} }
] ]
}, },
{ {
"name": "client-spoof", "name": "theme",
"description": "Spoofs the YouTube or Vanced client to prevent playback issues.", "description": "Enables a custom theme.",
"version": "0.0.1", "version": "0.0.1",
"excluded": false, "excluded": false,
"dependencies": [], "deprecated": false,
"options": [
{
"key": "theme",
"title": "Theme",
"description": "Select a theme.",
"required": true,
"choices": [
"Amoled"
]
}
],
"dependencies": [
"locale-config-fix"
],
"compatiblePackages": [ "compatiblePackages": [
{ {
"name": "com.google.android.youtube", "name": "com.google.android.youtube",
"versions": [] "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": [] "versions": []
} }
] ]

View file

@ -3,14 +3,17 @@ package app.revanced.meta.json
import app.revanced.meta.Bundle import app.revanced.meta.Bundle
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.dependencies 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.description
import app.revanced.patcher.extensions.PatchExtensions.include 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.patchName
import app.revanced.patcher.extensions.PatchExtensions.version 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 import java.io.File
private val gson = Gson() private val gson = GsonBuilder().serializeNulls().create()
fun generateJson(bundle: Bundle) { fun generateJson(bundle: Bundle) {
val patches = bundle.map { val patches = bundle.map {
@ -19,6 +22,20 @@ fun generateJson(bundle: Bundle) {
it.description ?: "This patch has no description.", it.description ?: "This patch has no description.",
it.version ?: "0.0.0", it.version ?: "0.0.0",
!it.include, !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 -> it.dependencies?.map { dep ->
dep.java.patchName dep.java.patchName
}?.toTypedArray() ?: emptyArray(), }?.toTypedArray() ?: emptyArray(),

View file

@ -7,6 +7,8 @@ data class JsonPatch(
val description: String, val description: String,
val version: String, val version: String,
val excluded: Boolean, val excluded: Boolean,
val deprecated: Boolean,
val options: Array<Option>,
val dependencies: Array<String>, val dependencies: Array<String>,
val compatiblePackages: Array<CompatiblePackage>, val compatiblePackages: Array<CompatiblePackage>,
) )
@ -14,4 +16,12 @@ data class JsonPatch(
data class CompatiblePackage( data class CompatiblePackage(
val name: String, val name: String,
val versions: Array<String>, val versions: Array<String>,
)
data class Option(
val key: String,
val title: String,
val description: String,
val required: Boolean,
val choices: Array<*>?,
) )