Skip to content

Commit

Permalink
feat(Twitter/X): Use chooser when opening links
Browse files Browse the repository at this point in the history
  • Loading branch information
dic1911 committed Feb 15, 2024
1 parent e86389e commit 6595c4b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,12 @@ public final class app/revanced/patches/twitter/layout/viewcount/HideViewCountPa
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/twitter/misc/browserchooser/BrowserChooserPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/twitter/misc/browserchooser/BrowserChooserPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch : app/revanced/patcher/patch/ResourcePatch {
public static final field INSTANCE Lapp/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch;
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package app.revanced.patches.twitter.misc.browserchooser

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.twitter.misc.browserchooser.fingerprints.OpenLinkFingerprint
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.util.exception
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
import com.android.tools.smali.dexlib2.Opcode
import java.lang.IllegalStateException

@Patch(
name = "Open browser chooser on opening links",
description = "Instead of open the link directly in one of the installed browsers",
compatiblePackages = [CompatiblePackage("com.twitter.android")]
)
@Suppress("unused")
object BrowserChooserPatch : BytecodePatch(
setOf(OpenLinkFingerprint)
) {
override fun execute(context: BytecodeContext) {

val result = OpenLinkFingerprint.result
?: throw IllegalStateException("Fingerprint not found")

val inject = """
invoke-static {p0, p1}, Lapp/revanced/integrations/twitter/patches/hook/patch/browserchooser/BrowserChooserHook->open(Landroid/content/Context;Landroid/content/Intent;)V
return-void
""".trimIndent()

result.mutableMethod.addInstructions(0, inject)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package app.revanced.patches.twitter.misc.browserchooser.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint


internal object OpenLinkFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("Landroid/content/Context;", "Landroid/content/Intent;", "Landroid/os/Bundle;")
)

0 comments on commit 6595c4b

Please sign in to comment.