mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2026-01-11 13:56:16 +00:00
fix: Suppress logger when loading patches in PatchBundleLoader
This commit is contained in:
@@ -47,7 +47,7 @@ sealed class PatchBundleLoader private constructor(
|
|||||||
}.filter {
|
}.filter {
|
||||||
Patch::class.java.isAssignableFrom(it)
|
Patch::class.java.isAssignableFrom(it)
|
||||||
}.mapNotNull { patchClass ->
|
}.mapNotNull { patchClass ->
|
||||||
patchClass.getInstance(logger)
|
patchClass.getInstance(logger, silent = true)
|
||||||
}.filter {
|
}.filter {
|
||||||
it.name != null
|
it.name != null
|
||||||
}.let { patches ->
|
}.let { patches ->
|
||||||
@@ -60,13 +60,14 @@ sealed class PatchBundleLoader private constructor(
|
|||||||
* Instantiates a [Patch]. If the class is a singleton, the INSTANCE field will be used.
|
* Instantiates a [Patch]. If the class is a singleton, the INSTANCE field will be used.
|
||||||
*
|
*
|
||||||
* @param logger The [Logger] to use for logging.
|
* @param logger The [Logger] to use for logging.
|
||||||
|
* @param silent Whether to suppress logging.
|
||||||
* @return The instantiated [Patch] or `null` if the [Patch] could not be instantiated.
|
* @return The instantiated [Patch] or `null` if the [Patch] could not be instantiated.
|
||||||
*/
|
*/
|
||||||
internal fun Class<*>.getInstance(logger: Logger): Patch<*>? {
|
internal fun Class<*>.getInstance(logger: Logger, silent: Boolean = false): Patch<*>? {
|
||||||
return try {
|
return try {
|
||||||
getField("INSTANCE").get(null)
|
getField("INSTANCE").get(null)
|
||||||
} catch (exception: NoSuchFieldException) {
|
} catch (exception: NoSuchFieldException) {
|
||||||
logger.fine(
|
if (!silent) logger.fine(
|
||||||
"Patch class '${name}' has no INSTANCE field, therefor not a singleton. " +
|
"Patch class '${name}' has no INSTANCE field, therefor not a singleton. " +
|
||||||
"Will try to instantiate it."
|
"Will try to instantiate it."
|
||||||
)
|
)
|
||||||
@@ -74,7 +75,7 @@ sealed class PatchBundleLoader private constructor(
|
|||||||
try {
|
try {
|
||||||
getDeclaredConstructor().newInstance()
|
getDeclaredConstructor().newInstance()
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
logger.severe(
|
if (!silent) logger.severe(
|
||||||
"Patch class '${name}' is not singleton and has no suitable constructor, " +
|
"Patch class '${name}' is not singleton and has no suitable constructor, " +
|
||||||
"therefor cannot be instantiated and will be ignored."
|
"therefor cannot be instantiated and will be ignored."
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user