diff --git a/README-template.md b/README-template.md index bd5e74d79..e6235c0e0 100644 --- a/README-template.md +++ b/README-template.md @@ -19,37 +19,28 @@ Example: { "name": "Alternative thumbnails", "description": "Adds options to replace video thumbnails using the DeArrow API or image captures from the video.", - "compatiblePackages":[ - { - "name": "com.google.android.youtube", - "versions": "COMPATIBLE_PACKAGE_YOUTUBE" - } - ], "use":true, + "compatiblePackages": { + "com.google.android.youtube": "COMPATIBLE_PACKAGE_YOUTUBE" + }, "options": [] }, { "name": "Bitrate default value", "description": "Sets the audio quality to 'Always High' when you first install the app.", - "compatiblePackages": [ - { - "name": "com.google.android.apps.youtube.music", - "versions": "COMPATIBLE_PACKAGE_MUSIC" - } - ], "use":true, + "compatiblePackages": { + "com.google.android.apps.youtube.music": "COMPATIBLE_PACKAGE_MUSIC" + }, "options": [] }, { "name": "Hide ads", "description": "Adds options to hide ads.", - "compatiblePackages": [ - { - "name": "com.reddit.frontpage", - "versions": "COMPATIBLE_PACKAGE_REDDIT" - } - ], "use":true, + "compatiblePackages": { + "com.reddit.frontpage": "COMPATIBLE_PACKAGE_REDDIT" + }, "options": [] } ] diff --git a/patches/src/main/kotlin/app/revanced/generator/JsonPatchesFileGenerator.kt b/patches/src/main/kotlin/app/revanced/generator/JsonPatchesFileGenerator.kt index dab126698..b06f3b3e5 100644 --- a/patches/src/main/kotlin/app/revanced/generator/JsonPatchesFileGenerator.kt +++ b/patches/src/main/kotlin/app/revanced/generator/JsonPatchesFileGenerator.kt @@ -1,10 +1,12 @@ package app.revanced.generator -import app.revanced.patcher.patch.Package import app.revanced.patcher.patch.Patch import com.google.gson.GsonBuilder import java.io.File +typealias PackageName = String +typealias VersionName = String + internal class JsonPatchesFileGenerator : PatchesFileGenerator { override fun generate(patches: Set>) { val patchesJson = File("../patches.json") @@ -12,8 +14,8 @@ internal class JsonPatchesFileGenerator : PatchesFileGenerator { JsonPatch( it.name!!, it.description, - it.compatiblePackages, it.use, + it.compatiblePackages?.associate { (packageName, versions) -> packageName to versions }, it.options.values.map { option -> JsonPatch.Option( option.key, @@ -26,27 +28,16 @@ internal class JsonPatchesFileGenerator : PatchesFileGenerator { }, ) }.let { - patchesJson.writeText(GsonBuilder().serializeNulls().create().toJson(it)) + patchesJson.writeText(GsonBuilder().setPrettyPrinting().create().toJson(it)) } - - patchesJson.writeText( - patchesJson.readText() - .replace( - "\"first\":", - "\"name\":" - ).replace( - "\"second\":", - "\"versions\":" - ) - ) } @Suppress("unused") private class JsonPatch( val name: String? = null, val description: String? = null, - val compatiblePackages: Set? = null, val use: Boolean = true, + val compatiblePackages: Map?>? = null, val options: List