Skip to content

Commit

Permalink
chore(JsonPatchesFileGenerator): Match patch list format with ReVance…
Browse files Browse the repository at this point in the history
…d API 4
  • Loading branch information
inotia00 committed Dec 21, 2024
1 parent a040b78 commit e611321
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
27 changes: 9 additions & 18 deletions README-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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<Patch<*>>) {
val patchesJson = File("../patches.json")
patches.sortedBy { it.name }.map {
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,
Expand All @@ -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<Package>? = null,
val use: Boolean = true,
val compatiblePackages: Map<PackageName, Set<VersionName>?>? = null,
val options: List<Option>,
) {
class Option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ internal class ReadMeFileGenerator : PatchesFileGenerator {
} else {
versions
?.toString()
?.replace("[", "[\n \"")
?.replace("]", "\"\n ]")
?.replace(", ", "\",\n \"")
?.replace("[", "[\n \"")
?.replace("]", "\"\n ]")
?.replace(", ", "\",\n \"")
?: "\"ALL\""
}

Expand Down

0 comments on commit e611321

Please sign in to comment.