feat(experimental): context menu fix

Attempt to repair the Friend Feed Menu as when the device is offline it cannot be displayed correctly

Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
rhunk 2024-06-05 15:32:14 +02:00
parent e45e96908b
commit 47a549ea2d
4 changed files with 31 additions and 0 deletions

View File

@ -1050,6 +1050,10 @@
"name": "Edit Messages",
"description": "Allows you to edit messages in conversations"
},
"context_menu_fix": {
"name": "Context Menu Fix",
"description": "Attempt to repair the Friend Feed Menu as when the device is offline it cannot be displayed correctly"
},
"app_lock": {
"name": "App Lock",
"description": "Prevents access to Snapchat without a passcode",

View File

@ -56,6 +56,7 @@ class Experimental : ConfigContainer() {
val callRecorder = boolean("call_recorder") { requireRestart(); addNotices(FeatureNotice.UNSTABLE); }
val accountSwitcher = container("account_switcher", AccountSwitcherConfig()) { requireRestart(); addNotices(FeatureNotice.UNSTABLE) }
val editMessage = boolean("edit_message") { requireRestart() }
val contextMenuFix = boolean("context_menu_fix") { requireRestart() }
val cofExperiments = multiple("cof_experiments", *cofExperimentList.toTypedArray()) { requireRestart(); addFlags(ConfigFlag.NO_TRANSLATE); addNotices(FeatureNotice.UNSTABLE) }
val appLock = container("app_lock", AppLockConfig()) { requireRestart(); addNotices(FeatureNotice.UNSTABLE) }
val infiniteStoryBoost = boolean("infinite_story_boost")

View File

@ -129,6 +129,7 @@ class FeatureManager(
ComposerHooks(),
DisableCustomTabs(),
BestFriendPinning(),
ContextMenuFix(),
)
initializeFeatures()
}

View File

@ -0,0 +1,25 @@
package me.rhunk.snapenhance.core.features.impl.experiments
import me.rhunk.snapenhance.core.event.events.impl.UnaryCallEvent
import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.FeatureLoadParams
import java.nio.ByteBuffer
class ContextMenuFix: Feature("Context Menu Fix", loadParams = FeatureLoadParams.INIT_SYNC) {
override fun init() {
if (!context.config.experimental.contextMenuFix.get()) return
context.event.subscribe(UnaryCallEvent::class) { event ->
if (event.uri == "/snapchat.maps.device.MapDevice/IsPrimary") {
event.canceled = true
val unaryEventHandler = event.adapter.arg<Any>(3)
runCatching {
unaryEventHandler::class.java.methods.first { it.name == "onEvent" }.invoke(unaryEventHandler, ByteBuffer.wrap(
byteArrayOf(8, 1)
), null)
}.onFailure {
context.log.error(null, it)
}
}
}
}
}