diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ConfigurationOverride.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ConfigurationOverride.kt index 4814ef713..07cc34b97 100644 --- a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ConfigurationOverride.kt +++ b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ConfigurationOverride.kt @@ -19,7 +19,7 @@ data class ConfigKeyInfo( data class ConfigFilter( val filter: (ConfigKeyInfo) -> Boolean, val defaultValue: (ConfigKeyInfo) -> Any?, - val isAppExperiment: Boolean = false + val isAppExperiment: Boolean? ) class ConfigurationOverride : Feature("Configuration Override", loadParams = FeatureLoadParams.INIT_SYNC) { @@ -67,7 +67,6 @@ class ConfigurationOverride : Feature("Configuration Override", loadParams = Fea arrayOf("CUSTOM_AD_TRACKER_URL", "CUSTOM_AD_INIT_SERVER_URL", "CUSTOM_AD_SERVER_URL", "INIT_PRIMARY_URL", "INIT_SHADOW_URL", "GRAPHENE_HOST").forEach { overrideProperty(it, { context.config.global.blockAds.get() }, { "http://127.0.0.1" }) } - overrideProperty("ENABLE_SNAP_FEED", { context.config.global.disableMemoriesSnapFeed.get() }, { false }) classReference.getAsClass()?.hook( getProperty.getAsString()!!, @@ -110,7 +109,7 @@ class ConfigurationOverride : Feature("Configuration Override", loadParams = Fea return@hook } propertyOverrides[keyInfo.name]?.let { (filter, value, isAppExperiment) -> - if (!isAppExperiment || !filter(keyInfo)) return@let + if (isAppExperiment != true || !filter(keyInfo)) return@let param.setResult(value(keyInfo)) } } @@ -134,7 +133,7 @@ class ConfigurationOverride : Feature("Configuration Override", loadParams = Fea } val propertyOverride = propertyOverrides[keyInfo.name] ?: return@hook - if (propertyOverride.isAppExperiment && propertyOverride.filter(keyInfo)) param.setResult(true) + propertyOverride.isAppExperiment.takeIf { propertyOverride.filter(keyInfo) }?.let { param.setResult(it) } } } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/global/DisableMemoriesSnapFeed.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/global/DisableMemoriesSnapFeed.kt new file mode 100644 index 000000000..e2aa19361 --- /dev/null +++ b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/global/DisableMemoriesSnapFeed.kt @@ -0,0 +1,27 @@ +package me.rhunk.snapenhance.core.features.impl.global + +import me.rhunk.snapenhance.core.features.Feature +import me.rhunk.snapenhance.core.features.FeatureLoadParams +import me.rhunk.snapenhance.core.util.hook.HookStage +import me.rhunk.snapenhance.core.util.hook.hook +import me.rhunk.snapenhance.mapper.impl.MemoriesPresenterMapper + +class DisableMemoriesSnapFeed : Feature("Disable Memories Snap Feed", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) { + override fun onActivityCreate() { + if (!context.config.global.disableMemoriesSnapFeed.get()) return + + context.mappings.useMapper(MemoriesPresenterMapper::class) { + classReference.get()?.apply { + val getNameMethod = getMethod("getName") ?: return@apply + + hook(onNavigationEventMethod.get()!!, HookStage.BEFORE) { param -> + val instance = param.thisObject() + + if (getNameMethod.invoke(instance) == "MemoriesAsyncPresenterFragmentSubscriber") { + param.setResult(null) + } + } + } + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt index fa4cec0cf..764525acc 100644 --- a/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt +++ b/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt @@ -121,6 +121,7 @@ class FeatureManager( SessionEvents(), DefaultVolumeControls(), CallRecorder(), + DisableMemoriesSnapFeed(), ) initializeFeatures() diff --git a/mapper/src/main/kotlin/me/rhunk/snapenhance/mapper/ClassMapper.kt b/mapper/src/main/kotlin/me/rhunk/snapenhance/mapper/ClassMapper.kt index 86843ba96..0445cee94 100644 --- a/mapper/src/main/kotlin/me/rhunk/snapenhance/mapper/ClassMapper.kt +++ b/mapper/src/main/kotlin/me/rhunk/snapenhance/mapper/ClassMapper.kt @@ -34,6 +34,7 @@ class ClassMapper( ViewBinderMapper(), FriendingDataSourcesMapper(), OperaViewerParamsMapper(), + MemoriesPresenterMapper(), ) } diff --git a/mapper/src/main/kotlin/me/rhunk/snapenhance/mapper/impl/MemoriesPresenterMapper.kt b/mapper/src/main/kotlin/me/rhunk/snapenhance/mapper/impl/MemoriesPresenterMapper.kt new file mode 100644 index 000000000..64fd70474 --- /dev/null +++ b/mapper/src/main/kotlin/me/rhunk/snapenhance/mapper/impl/MemoriesPresenterMapper.kt @@ -0,0 +1,25 @@ +package me.rhunk.snapenhance.mapper.impl + +import me.rhunk.snapenhance.mapper.AbstractClassMapper +import me.rhunk.snapenhance.mapper.ext.findConstString +import me.rhunk.snapenhance.mapper.ext.getClassName + +class MemoriesPresenterMapper : AbstractClassMapper("MemoriesPresenter") { + val classReference = classReference("class") + val onNavigationEventMethod = string("onNavigationEventMethod") + + init { + mapper { + for (clazz in classes) { + if (clazz.interfaces.size != 1) continue + val getNameMethod = clazz.methods.firstOrNull { it.name == "getName" } ?: continue + if (getNameMethod.implementation?.findConstString("MemoriesAsyncPresenterFragmentSubscriber") != true) continue + + val onNavigationEvent = clazz.methods.firstOrNull { it.implementation?.findConstString("Memories") == true } ?: continue + + classReference.set(clazz.getClassName()) + onNavigationEventMethod.set(onNavigationEvent.name) + } + } + } +} \ No newline at end of file