mirror of
https://github.com/revanced/revanced-manager-compose
synced 2025-02-20 18:16:48 +01:00
refactor: better PatchBundle docs and naming
This commit is contained in:
parent
909266daf4
commit
1ffaf43b82
@ -12,10 +12,12 @@ import java.io.File
|
|||||||
class PatchBundle(private val loader: Iterable<PatchClass>, val integrations: File?) {
|
class PatchBundle(private val loader: Iterable<PatchClass>, val integrations: File?) {
|
||||||
constructor(bundleJar: File, integrations: File?) : this(
|
constructor(bundleJar: File, integrations: File?) : this(
|
||||||
object : Iterable<PatchClass> {
|
object : Iterable<PatchClass> {
|
||||||
private val bundle = PatchBundle.Dex(
|
private val bundle = bundleJar.absolutePath.let {
|
||||||
bundleJar.absolutePath,
|
PatchBundle.Dex(
|
||||||
PathClassLoader(bundleJar.absolutePath, Patcher::class.java.classLoader)
|
it,
|
||||||
)
|
PathClassLoader(it, Patcher::class.java.classLoader)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override fun iterator() = bundle.loadPatches().iterator()
|
override fun iterator() = bundle.loadPatches().iterator()
|
||||||
},
|
},
|
||||||
@ -24,12 +26,15 @@ class PatchBundle(private val loader: Iterable<PatchClass>, val integrations: Fi
|
|||||||
Log.d(tag, "Loaded patch bundle: $bundleJar")
|
Log.d(tag, "Loaded patch bundle: $bundleJar")
|
||||||
}
|
}
|
||||||
|
|
||||||
val patches = loadAllPatches().map(::PatchInfo)
|
/**
|
||||||
|
* A list containing the metadata of every patch inside this bundle.
|
||||||
|
*/
|
||||||
|
val patches = loader.map(::PatchInfo)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A list of patches that are compatible with this Apk.
|
* Load all patches compatible with the specified package.
|
||||||
*/
|
*/
|
||||||
fun loadPatchesFiltered(packageName: String) = loader.filter { patch ->
|
fun patchClasses(packageName: String) = loader.filter { patch ->
|
||||||
val compatiblePackages = patch.compatiblePackages
|
val compatiblePackages = patch.compatiblePackages
|
||||||
?: // The patch has no compatibility constraints, which means it is universal.
|
?: // The patch has no compatibility constraints, which means it is universal.
|
||||||
return@filter true
|
return@filter true
|
||||||
@ -41,6 +46,4 @@ class PatchBundle(private val loader: Iterable<PatchClass>, val integrations: Fi
|
|||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadAllPatches() = loader.toList()
|
|
||||||
}
|
}
|
@ -120,7 +120,7 @@ class PatcherWorker(context: Context, parameters: WorkerParameters) :
|
|||||||
|
|
||||||
return try {
|
return try {
|
||||||
val patchList = args.selectedPatches.flatMap { (bundleName, selected) ->
|
val patchList = args.selectedPatches.flatMap { (bundleName, selected) ->
|
||||||
bundles[bundleName]?.loadPatchesFiltered(args.packageName)
|
bundles[bundleName]?.patchClasses(args.packageName)
|
||||||
?.filter { selected.contains(it.patchName) }
|
?.filter { selected.contains(it.patchName) }
|
||||||
?: throw IllegalArgumentException("Patch bundle $bundleName does not exist")
|
?: throw IllegalArgumentException("Patch bundle $bundleName does not exist")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user